Class: Scc::Commands::BuildManifestFromGit

Inherits:
Object
  • Object
show all
Defined in:
lib/scc/commands/build_manifest_from_git.rb

Instance Method Summary collapse

Instance Method Details

#call(argv) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/scc/commands/build_manifest_from_git.rb', line 37

def call(argv)
  argv = %w[-h] if argv.empty?
  options = parse_args(argv)

  # early exits
  return options[:early_exit] if options[:early_exit]

  deploy_info = Scc::DeployInfo.from_git(root: options[:git_root])
  deploy_info.extract!

  open_and_yield(options[:output_file]) do |f|
    f.puts(YAML.dump(deploy_info.to_poro))
  end

  0
rescue Scc::DeployInfo::Extractor::Git::NotAGitRootError => e
  puts e.message
  1
end

#parse_args(argv) ⇒ Object



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
# File 'lib/scc/commands/build_manifest_from_git.rb', line 10

def parse_args(argv)
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: scc-build-deploy-manifest-from-git [options]"

    opts.on("-o", "--output FILE", "Output file") do |file|
      options[:output_file] = file
    end

    opts.on("-d", "--git-dir PATH", "Git root") do |git_root|
      options[:git_root] = git_root
    end

    opts.on("-h", "--help", "Prints this help") do
      options[:early_exit] = true
      puts opts
    end

    opts.on("-v", "--version", "Prints gem version") do
      options[:early_exit] = true
      puts Scc::VERSION
    end
  end.parse!(argv)

  options
end