Class: Honey::CLI
- Inherits:
-
Object
- Object
- Honey::CLI
- Defined in:
- lib/honey/cli.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #parse_options!(args) ⇒ Object
- #run(args, options) ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
8 9 10 11 |
# File 'lib/honey/cli.rb', line 8 def initialize(args) = (args) run(args, ) end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/honey/cli.rb', line 6 def command @command end |
Instance Method Details
#parse_options!(args) ⇒ Object
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 |
# File 'lib/honey/cli.rb', line 19 def (args) @command = nil = {} = OptionParser.new do |opts| opts.on("--path [PATH]") do |path| [:path] = path end opts.on("--output [PATH]") do |path| [:output] = path end opts.on("--api_host API_HOST") do |api_host| [:api_host] = api_host end opts.on("--api-name API_HOST") do |api_name| [:api_name] = api_name end opts.on("--browser BROWSER") do |browser| [:browser] = browser end opts.on("--server") do [:server] = true end opts.on("--port [PORT]") do |port| [:port] = port end opts.on('-v', '--version') do @command = :version end opts.on( '-h', '--help') do @command = :help end end .parse! rescue OptionParser::InvalidOption => e puts e puts Honey::Command::Help. exit 1 end |
#run(args, options) ⇒ Object
13 14 15 16 17 |
# File 'lib/honey/cli.rb', line 13 def run(args, ) command = args.first || :help command = @command if @command Honey::Command::Runner.run(command, ) end |