Class: Gemnasium::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/gemnasium/options.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Hash, OptionParser

Parse arguments from command line

Parameters:

  • args (Array)

    arguments from command line

Returns:

  • (Hash, OptionParser)

    hash of the parsed options & Option parser to get --help message



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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gemnasium/options.rb', line 10

def self.parse args
  options = {}

  global = OptionParser.new do |opts|
    opts.banner = 'Usage: gemnasium [options]'

    opts.on '-v', '--version', 'Show Gemnasium version' do
      options[:show_version] = true
    end

    opts.on '-h', '--help', 'Display this message' do
      options[:show_help] = true
    end

    opts.separator ''
    opts.separator <<-HELP_MESSAGE
Available commands are:
  create   :   Create or update project on Gemnasium
  install  :   Install the necessary config file
  push     :   Push your dependency files to Gemnasium
  migrate  :   Migrate the configuration file
  resolve  :   Resolve project name to an existing project on Gemnasium

See `gemnasium COMMAND --help` for more information on a specific command.

WARNING! The gemnasium Rubygem has been deprecated.
Please use Gemnasium Toolbelt (https://github.com/gemnasium/toolbelt) instead.
    HELP_MESSAGE
  end

  subcommands = {
    'create'  => OptionParser.new do |opts|
      opts.banner = 'Usage: gemnasium create [options]'

      opts.on '-h', '--help', 'Display this message' do
        options[:show_help] = true
      end
    end,
    'install' => OptionParser.new do |opts|
      opts.banner = 'Usage: gemnasium install [options]'

      opts.on '--git', 'Create a post-commit hook to run gemnasium push command if a dependency file has been commited' do
        options[:install_git_hook] = true
      end

      opts.on '--rake', 'Create rake task to run Gemnasium' do
        options[:install_rake_task] = true
      end

      opts.on '-h', '--help', 'Display this message' do
        options[:show_help] = true
      end
    end,
    'push'    => OptionParser.new do |opts|
      opts.banner = 'Usage: gemnasium push'

      opts.on '-i', '--ignore-branch', 'Push to gemnasium regardless of branch' do
        options[:ignore_branch] = true
      end

      opts.on '-s', '--silence-branch', 'Silently ignore untracked branches' do
        options[:silence_branch] = true
      end

      opts.on '-h', '--help', 'Display this message' do
        options[:show_help] = true
      end
    end,
    'migrate'  => OptionParser.new do |opts|
      opts.banner = 'Usage: gemnasium migrate [options]'

      opts.on '-h', '--help', 'Display this message' do
        options[:show_help] = true
      end
    end,
    'resolve'  => OptionParser.new do |opts|
      opts.banner = 'Usage: gemnasium resolve [options]'

      opts.on '-h', '--help', 'Display this message' do
        options[:show_help] = true
      end
    end
  }

  global.order! args
  parser = global

  unless (command = args.shift).nil?
    raise OptionParser::ParseError unless subcommands.has_key?(command)
    subcommands[command].order! args
    options[:command] = command
    parser = subcommands[command]
  end

  return options, parser
end