Class: Maintainers::CLI
- Inherits:
-
Object
- Object
- Maintainers::CLI
- Defined in:
- lib/maintainers/cli.rb
Overview
CLI entry point
Constant Summary collapse
- SUBCOMMANDS_WE_LOVE =
[ "create", "add", "remove", "list", "report", "help", "--help", ]
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
-
#parse(args) ⇒ Hash
Return an options hash.
-
#run(args = ARGV) ⇒ Fixnum
Exit code.
- #usage ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
11 12 13 |
# File 'lib/maintainers/cli.rb', line 11 def initialize @options = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/maintainers/cli.rb', line 9 def @options end |
Instance Method Details
#parse(args) ⇒ Hash
Return an options hash
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 |
# File 'lib/maintainers/cli.rb', line 31 def parse(args) subcommands = { 'create' => OptionParser.new do |opts| opts.on("-i", "--issues [ISSUES URL]", "issues url") do |v| [:issues] = v end end, 'add' => OptionParser.new do |opts| opts.on("-g", "--github [GITHUB ID]", "github id") do |v| [:github] = v end opts.on("-e", "--email [EMAIL ADDRESS]", "email address") do |v| [:email] = v end opts.on("-n", "--name [REAL NAME]", "real name") do |v| [:name] = v end end, 'remove' => OptionParser.new do |opts| opts.on("-g", "--github [GITHUB ID]", "github id") do |v| [:github] = v end end, 'list' => OptionParser.new do |opts| end, } if args.count == 0 $stderr.puts "Give me some args please" usage end subcommand = args.shift [:subcommand] = subcommand unless subcommands.keys.include? subcommand usage end subcommands[subcommand].order! if subcommand == 'create' && [:issues].nil? $stderr.puts "Please specify --issues" usage end if subcommand == 'add' && [:github].nil? $stderr.puts "Please specify --github" usage end if args.count > 0 $stderr.puts "Unexpected additional args #{args}" usage end end |
#run(args = ARGV) ⇒ Fixnum
Returns exit code.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/maintainers/cli.rb', line 92 def run(args = ARGV) @options = parse(args) runner = Runner.new(@options) runner.run rescue StandardError, SyntaxError => e $stderr.puts e. $stderr.puts e.backtrace return 1 end |
#usage ⇒ Object
15 16 17 18 |
# File 'lib/maintainers/cli.rb', line 15 def usage puts "Imagine a usage statement here" exit 1 end |