Class: OKF::CLI::Registry
Overview
The registry umbrella, split by what each verb keys on. set/del/list
act on entries — set keys on the bundle's path, so --as means one thing
("the slug this entry has") whether it adds or renames. default/rename
act on slugs, the names actually to hand once a bundle is registered. Every
positional stays unambiguous, and config is left free for real settings.
Constant Summary collapse
- SUBCOMMANDS =
The
registryumbrella's subcommands — the dispatch, and the words a flag-first invocation is checked against. %w[init set del list default rename group ungroup].freeze
Constants inherited from Command
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Command
Constructor Details
This class inherits a constructor from OKF::CLI::Command
Class Method Details
.group ⇒ Object
19 20 21 |
# File 'lib/okf/cli/registry.rb', line 19 def self.group :registry end |
.help_rows ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/okf/cli/registry.rb', line 23 def self.help_rows [ [ "registry init", "create a project-local .okf-registry.json (nearest one wins)" ], [ "registry list [--json]", "list registered bundles (* marks the default)" ], [ "registry set <dir|@slug> [--as SLUG] [--default]", "add or update a bundle (a bare `server` serves them)" ], [ "registry del <dir|@slug>", "remove a bundle or group from the registry" ], [ "registry default <@slug>", "move a bundle to the front (the default)" ], [ "registry rename <@slug> <new>", "rename a bundle or group (<new> is a new name, not a ref)" ], [ "registry group <slug> <@member…>", "create a group, or add members (search/server can target @slug)" ], [ "registry ungroup <slug> <@member…>", "remove members from a group (emptying it deletes it)" ] ] end |
.id ⇒ Object
15 16 17 |
# File 'lib/okf/cli/registry.rb', line 15 def self.id :registry end |
Instance Method Details
#call(argv) ⇒ Object
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 |
# File 'lib/okf/cli/registry.rb', line 36 def call(argv) require "okf/registry" sub = argv.first case sub when "init" then registry_init(argv.drop(1)) when "set" then registry_set(argv.drop(1)) when "del" then registry_del(argv.drop(1)) when "list" then registry_list(argv.drop(1)) when "default" then registry_default(argv.drop(1)) when "rename" then registry_rename(argv.drop(1)) when "group" then registry_group(argv.drop(1)) when "ungroup" then registry_ungroup(argv.drop(1)) else # A bare word that isn't a known subcommand is a typo (`registry remove x` # must not silently render the list and read as success). return usage_error("unknown registry subcommand '#{sub}' (expected: #{SUBCOMMANDS.join(", ")})") if sub && !sub.start_with?("-") # Same rule for a subcommand hiding behind a flag: `registry --json set # dir` would otherwise list an empty registry and exit 0, having written # nothing the user asked for. It cannot just be dispatched from wherever # it turns up — the word may be a flag's value (`registry --as set <dir>` # asks for the slug "set"), and a grammar where that reading depends on # which flag precedes it is a trapdoor. So the subcommand must lead, and # the error says which one was found rather than guessing at the intent. stray = argv.find { |arg| SUBCOMMANDS.include?(arg) } return usage_error("put the subcommand first: okf registry #{stray} … (flags follow it)") if stray registry_list(argv) end end |