Class: DevContext::CLI
- Inherits:
-
Object
- Object
- DevContext::CLI
- Includes:
- DevContext::Commands::ContextLifecycle, DevContext::Commands::Doctor, DevContext::Commands::Find, DevContext::Commands::GitOps, DevContext::Commands::Help, DevContext::Commands::Init, DevContext::Commands::Remove, DevContext::Commands::Repos, DevContext::Commands::SearchHelpers, DevContext::Commands::Stashes, DevContext::Commands::Status, DevContext::Commands::Support
- Defined in:
- lib/dev_context/cli.rb
Constant Summary collapse
- COLOR_RESET =
"\e[0m"- COLOR_ORANGE =
"\e[38;5;208m"- COLOR_CYAN =
"\e[36m"- COLOR_GREEN =
"\e[32m"- COLOR_RED =
"\e[31m"- COLOR_YELLOW =
"\e[33m"- COLOR_MAGENTA =
"\e[35m"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, out:, err:, env:, pwd:, stdin: STDIN) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Methods included from DevContext::Commands::Remove
Methods included from DevContext::Commands::Status
Methods included from DevContext::Commands::Stashes
Methods included from DevContext::Commands::Repos
Methods included from DevContext::Commands::Find
Methods included from DevContext::Commands::Doctor
Methods included from DevContext::Commands::GitOps
#cmd_active, #cmd_branches, #cmd_checkout, #cmd_deactivate, #cmd_diff, #cmd_pop, #cmd_push
Methods included from DevContext::Commands::ContextLifecycle
#cmd_activate, #cmd_add, #cmd_clone, #cmd_create
Methods included from DevContext::Commands::Help
Methods included from DevContext::Commands::Init
Constructor Details
#initialize(argv, out:, err:, env:, pwd:, stdin: STDIN) ⇒ CLI
Returns a new instance of CLI.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dev_context/cli.rb', line 35 def initialize(argv, out:, err:, env:, pwd:, stdin: STDIN) @argv = argv.dup @out = out @err = err @env = env @pwd = pwd @stdin = stdin @config = Config.new @matcher = Matcher.new(config: @config) end |
Class Method Details
.run(argv, out: $stdout, err: $stderr, env: ENV, pwd: Dir.pwd, stdin: STDIN) ⇒ Object
31 32 33 |
# File 'lib/dev_context/cli.rb', line 31 def self.run(argv, out: $stdout, err: $stderr, env: ENV, pwd: Dir.pwd, stdin: STDIN) new(argv, out: out, err: err, env: env, pwd: pwd, stdin: stdin).run end |
Instance Method Details
#run ⇒ Object
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 90 91 92 93 |
# File 'lib/dev_context/cli.rb', line 46 def run raw_command = argv.shift return default_action if raw_command.nil? raw_command = "version" if %w[--version -V].include?(raw_command) resolution = resolve_command(raw_command) command = resolution[:command] if command.nil? if resolution[:error] == :unknown && !raw_command.start_with?("-") argv.unshift(raw_command) return cmd_find end return 1 end if %w[--help -h].include?(argv.first) argv.shift return cmd_help_topic(command) end case command when "version" then cmd_version when "init" then cmd_init when "help", "--help", "-h" then cmd_help when "add" then cmd_add when "clone" then cmd_clone when "create" then cmd_create when "remove" then cmd_remove when "active" then cmd_active when "deactivate" then cmd_deactivate when "doctor", "check" then cmd_doctor when "find" then cmd_find when "stashes" then cmd_stashes when "repos" then cmd_repos when "status", "wip" then cmd_status(mode: command) when "diff" then cmd_diff when "branches", "br" then cmd_branches when "co", "checkout" then cmd_checkout when "pushd" then cmd_push when "cd", "activate" then cmd_activate when "popd" then cmd_pop else err.puts("dx: unknown command '#{raw_command}'") cmd_help 1 end end |