Class: VScripts::CommandLine
- Inherits:
-
Object
- Object
- VScripts::CommandLine
- Defined in:
- lib/vscripts/command_line.rb
Overview
Global Command Line
Instance Attribute Summary collapse
-
#arguments ⇒ Array
All the command line arguments.
-
#command ⇒ String
readonly
Command name.
-
#global ⇒ Hash
readonly
Global command line arguments.
Instance Method Summary collapse
-
#initialize(argv = []) ⇒ CommandLine
constructor
Build command line arguments.
-
#parse_cli_options ⇒ Object
Parses command line arguments.
-
#parser ⇒ Object
Specifies command line options This method smells of :reek:NestedIterators but ignores them This method smells of :reek:TooManyStatements but ignores them.
-
#verify_command ⇒ String
Ensure command is available.
Constructor Details
#initialize(argv = []) ⇒ CommandLine
Build command line arguments
16 17 18 19 20 |
# File 'lib/vscripts/command_line.rb', line 16 def initialize(argv = []) @arguments ||= argv @global ||= @command ||= verify_command end |
Instance Attribute Details
#arguments ⇒ Array
Returns All the command line arguments.
9 10 11 |
# File 'lib/vscripts/command_line.rb', line 9 def arguments @arguments end |
#command ⇒ String (readonly)
Returns Command name.
13 14 15 |
# File 'lib/vscripts/command_line.rb', line 13 def command @command end |
#global ⇒ Hash (readonly)
Returns Global command line arguments.
11 12 13 |
# File 'lib/vscripts/command_line.rb', line 11 def global @global end |
Instance Method Details
#parse_cli_options ⇒ Object
Parses command line arguments
48 49 50 51 52 53 |
# File 'lib/vscripts/command_line.rb', line 48 def Trollop.with_standard_exception_handling parser do fail Trollop::HelpNeeded if arguments.empty? parser.parse arguments end end |
#parser ⇒ Object
Specifies command line options This method smells of :reek:NestedIterators but ignores them This method smells of :reek:TooManyStatements but ignores them
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vscripts/command_line.rb', line 25 def parser # rubocop:disable MethodLength available = Command.list.map { |cmd| cmd.to_s.downcase } @parser ||= Trollop::Parser.new do version VScripts::VERSION_C <<-EOS VScripts automation daemon. Available commands: #{available} Usage: vscripts GLOBAL-OPTIONS COMMAND OPTIONS For help on an individual command: vscripts COMMAND --help Global Options: EOS stop_on available end end |
#verify_command ⇒ String
Ensure command is available
57 58 59 60 61 62 63 64 65 |
# File 'lib/vscripts/command_line.rb', line 57 def verify_command command_cli = arguments.shift command_cls = command_cli.capitalize.to_sym if Command.list.include?(command_cls) return command_cls else abort "Error: Unknown subcommand '#{command_cli}'\nTry --help." end end |