Class: Appydave::Tools::Jump::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/jump/cli.rb

Overview

CLI provides the command-line interface for the Jump tool

Uses the Method Dispatch (Full) pattern for 10+ commands with hierarchical help system.

Examples:

Usage

cli = CLI.new
cli.run(['search', 'appydave', 'ruby'])
cli.run(['add', '--key', 'my-project', '--path', '~/dev/project'])

Constant Summary collapse

EXIT_SUCCESS =
0
EXIT_NOT_FOUND =
1
EXIT_INVALID_INPUT =
2
EXIT_CONFIG_ERROR =
3
EXIT_PATH_NOT_FOUND =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: nil, path_validator: nil, output: $stdout) ⇒ CLI

Returns a new instance of CLI.



24
25
26
27
28
# File 'lib/appydave/tools/jump/cli.rb', line 24

def initialize(config: nil, path_validator: nil, output: $stdout)
  @path_validator = path_validator || PathValidator.new
  @output = output
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/appydave/tools/jump/cli.rb', line 22

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



22
23
24
# File 'lib/appydave/tools/jump/cli.rb', line 22

def output
  @output
end

#path_validatorObject (readonly)

Returns the value of attribute path_validator.



22
23
24
# File 'lib/appydave/tools/jump/cli.rb', line 22

def path_validator
  @path_validator
end

Instance Method Details

#run(args = ARGV) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize



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
# File 'lib/appydave/tools/jump/cli.rb', line 31

def run(args = ARGV)
  command = args.shift

  case command
  when nil, '', '--help', '-h'
    show_main_help
    EXIT_SUCCESS
  when '--version', '-v'
    show_version
    EXIT_SUCCESS
  when 'help'
    show_help(args)
    EXIT_SUCCESS
  when 'search'
    run_search(args)
  when 'get'
    run_get(args)
  when 'list'
    run_list(args)
  when 'add'
    run_add(args)
  when 'update'
    run_update(args)
  when 'remove'
    run_remove(args)
  when 'validate'
    run_validate(args)
  when 'report'
    run_report(args)
  when 'generate'
    run_generate(args)
  when 'info'
    run_info(args)
  else
    output.puts "Unknown command: #{command}"
    output.puts "Run 'jump help' for available commands."
    EXIT_INVALID_INPUT
  end
rescue StandardError => e
  output.puts "Error: #{e.message}"
  output.puts e.backtrace.first(3).join("\n") if ENV['DEBUG']
  EXIT_CONFIG_ERROR
end