Class: Salmon::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/salmon/config.rb

Class Method Summary collapse

Class Method Details

.parse_options(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/salmon/config.rb', line 5

def self.parse_options(args)
    options = OpenStruct.new

    path = File.expand_path('~/.salmon')
    abort("Please create a YAML server config file at ~/.salmon") if not File.readable?(path)
    githubs = YAML.load(File.read(path))

    options.temp_path = 'salmon'
    options.push_tags = true
    options.push_branches = ['*']
    options.verbose = true

    OptionParser.new do |opts|
        opts.banner = "Usage: salmon [options]"

        opts.separator ""
        opts.separator "Available sites:"
        opts.separator githubs.keys.join(", ")
        opts.separator ""

        opts.on("-s", "--source [SITE:ACCOUNT]", "Site name or source:destination string. Available: #{githubs.keys.join(', ')}") do |source|
            source = source.split(":")
            options.source = OpenStruct.new(githubs[source.first])
            options.source.name = source.last
        end

        opts.on("-t", "--target [SITE:ACCOUNT]", "Organization or user name(s). Source only or source:destination.") do |source|
            source = source.split(":")
            options.dest = OpenStruct.new(githubs[source.first])
            options.dest.name = source.last
        end

        #TODO: clone only might be nice

        opts.on("-p", "--tags", "Include tags when pushing") do |v|
            options.push_tags = v
        end

        opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
            options[:verbose] = v
        end

        opts.on_tail("--version", "Show version") do
            puts Salmon::VERSION
            exit
        end
    end.parse!(args)
    self.validate!(options)
    options
end

.validate!(options) ⇒ Object



56
57
58
59
60
61
# File 'lib/salmon/config.rb', line 56

def self.validate!(options)
    {source: options.source, destination: options.dest}.each do |title, settings|
        abort("You must include #{title.to_s} settings") if settings.nil?
        abort("Please include name for both #{title.to_s} account") if settings.name.nil?
    end
end