Class: Onetime::CLI::Parser
- Inherits:
-
Object
- Object
- Onetime::CLI::Parser
- Defined in:
- lib/onetime/cli/parser.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_COMMAND =
'share'.freeze
- KNOWN_COMMANDS =
%w[status receipt secret share generate].freeze
- COMMAND_ALIASES =
{ 'get' => 'secret' }.freeze
- VALID_FORMATS =
%w[json yaml csv].freeze
- COMMAND_OPTIONS =
{ 'share' => %i[ttl passphrase recipient].freeze, 'generate' => %i[ttl passphrase recipient].freeze, 'secret' => %i[passphrase].freeze, 'receipt' => [].freeze, 'status' => [].freeze, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(argv) ⇒ Parser
Returns a new instance of Parser.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/onetime/cli/parser.rb', line 35 def initialize(argv) @argv = argv.dup @base_uri = nil @custid = nil @apikey = nil @global_recipients = [] @command_recipients = [] @format = nil @debug = false @show_version = false @ttl = nil @passphrase = nil @yaml_flag = false @json_flag = false @string_flag = false end |
Class Method Details
.parse(argv) ⇒ Object
31 32 33 |
# File 'lib/onetime/cli/parser.rb', line 31 def self.parse(argv) new(argv).parse end |
Instance Method Details
#parse ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/onetime/cli/parser.rb', line 52 def parse global_option_parser.order!(@argv) command, rest = extract_command if command command_option_parser(command).order!(rest) end apply_format_precedence! normalize_format! Result.new( command: command, argv: rest, base_uri: @base_uri, custid: @custid, apikey: @apikey, recipients: (@command_recipients + @global_recipients).uniq, format: @format, debug: @debug, show_version: @show_version, ttl: @ttl, passphrase: @passphrase, ) rescue OptionParser::ParseError => e raise Error, e. end |