Class: Klondikemarlen::JiraApi::CLI
- Inherits:
-
Object
- Object
- Klondikemarlen::JiraApi::CLI
- Defined in:
- lib/klondikemarlen/jira_api/cli.rb
Constant Summary collapse
- COMMANDS =
{ "list" => { required: %i[issue_key], action: :list_comments }, "get" => { required: %i[issue_key comment_id], action: :get_comment }, "create" => { required: %i[issue_key markdown_file], action: :create_comment }, "update" => { required: %i[issue_key comment_id markdown_file], action: :update_comment }, "delete" => { required: %i[issue_key comment_id], action: :delete_comment }, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, env:, out:, err:, client_factory: nil) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv, env:, out:, err:, client_factory: nil) ⇒ CLI
Returns a new instance of CLI.
21 22 23 24 25 26 27 |
# File 'lib/klondikemarlen/jira_api/cli.rb', line 21 def initialize(argv, env:, out:, err:, client_factory: nil) @argv = argv.dup @env = env @out = out @err = err @client_factory = client_factory || method(:build_client) end |
Class Method Details
.run(argv = ARGV, env: ENV, out: $stdout, err: $stderr, client_factory: nil) ⇒ Object
17 18 19 |
# File 'lib/klondikemarlen/jira_api/cli.rb', line 17 def self.run(argv = ARGV, env: ENV, out: $stdout, err: $stderr, client_factory: nil) new(argv, env:, out:, err:, client_factory:).run end |
Instance Method Details
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/klondikemarlen/jira_api/cli.rb', line 29 def run command = @argv.shift config = COMMANDS[command] return fail_with("Unknown command #{command.inspect}. Expected one of: #{COMMANDS.keys.join(", ")}") unless config = missing = config.fetch(:required).select { |key| [key].to_s.empty? } return fail_with("Missing required option(s): #{option_names(missing)}") unless missing.empty? @out.puts JSON.pretty_generate(send(config.fetch(:action), )) 0 rescue OptionParser::ParseError, KeyError => error fail_with(error.) end |