Class: SchwarmCli::Commands::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/schwarm_cli/commands/base.rb

Constant Summary collapse

INHERITED_OPTIONS =

Thor parses class_options at each subcommand level independently, so ‘–json` at a doubly-nested invocation (`agents subscriptions list –json`) is consumed by the outer class and never reaches the inner. Merge parent_options for global flags (json, url, token) so they propagate transparently into nested subcommands.

We can’t use Hash#merge with a block because Thor returns a HashWithIndifferentAccess whose ‘merge` ignores the block argument (lib/thor/core_ext/hash_with_indifferent_access.rb:53). Walk the inherited keys explicitly so an explicit child value (including `false` from –no-json) wins over an inherited parent value.

%w[json url token].freeze
DEFAULT_LIST_LIMIT =
20

Class Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


15
# File 'lib/schwarm_cli/commands/base.rb', line 15

def self.exit_on_failure? = true

.pagination_optionsObject

Declares –limit, –page, –all options for the next method.



44
45
46
47
48
49
# File 'lib/schwarm_cli/commands/base.rb', line 44

def self.pagination_options
  method_option :limit, type: :numeric,
                        desc: "Max results per page (default: #{DEFAULT_LIST_LIMIT})"
  method_option :page, type: :numeric, desc: "Page number (1-indexed)"
  method_option :all, type: :boolean, default: false, desc: "Fetch all pages (no cap)"
end