Class: Brick::CLI_Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/brick/cli__validator.rb

Constant Summary collapse

NO_COMMAND_GIVEN =
"You need to pass a sub-command (e.g., brick SUB-COMMAND)\n"

Class Method Summary collapse

Class Method Details

.no_command_given?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/brick/cli__validator.rb', line 16

def self.no_command_given?
  ARGV.empty?
end

.no_subcommand_given?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/brick/cli__validator.rb', line 12

def self.no_subcommand_given?
  ARGV[0] =~ /^-/
end


20
21
22
23
24
25
# File 'lib/brick/cli__validator.rb', line 20

def self.print_help_and_exit(exitcode=1, fatal_message=nil)
  Brick::CLI::logger.error(fatal_message) if fatal_message
  Brick::CLI.list_parameters
  Brick::CLI.list_commands
  exit exitcode
end

.validateObject



5
6
7
8
9
10
# File 'lib/brick/cli__validator.rb', line 5

def self.validate
  if  no_command_given?
    print_help_and_exit(1, NO_COMMAND_GIVEN)
  end
  
end