Module: Browserctl::Commands::Storage
- Extended by:
- CliOutput
- Defined in:
- lib/browserctl/commands/storage.rb
Constant Summary collapse
- USAGE =
"Usage: browserctl storage <get|set|export|import|delete> [args]"
Class Method Summary collapse
- .extract_opt(args, flag) ⇒ Object
- .run(client, args) ⇒ Object
- .run_delete(client, args) ⇒ Object
- .run_export(client, args) ⇒ Object
- .run_get(client, args) ⇒ Object
- .run_import(client, args) ⇒ Object
- .run_set(client, args) ⇒ Object
Methods included from CliOutput
Class Method Details
.extract_opt(args, flag) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/browserctl/commands/storage.rb', line 58 def self.extract_opt(args, flag) idx = args.index(flag) return nil unless idx args.delete_at(idx) args.delete_at(idx) end |
.run(client, args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/browserctl/commands/storage.rb', line 12 def self.run(client, args) sub = args.shift or abort USAGE case sub when "get" then run_get(client, args) when "set" then run_set(client, args) when "export" then run_export(client, args) when "import" then run_import(client, args) when "delete" then run_delete(client, args) else abort "unknown storage subcommand '#{sub}'\n#{USAGE}" end end |
.run_delete(client, args) ⇒ Object
52 53 54 55 56 |
# File 'lib/browserctl/commands/storage.rb', line 52 def self.run_delete(client, args) page = args.shift or abort "usage: browserctl storage delete <page> [--store local|session|all]" store = extract_opt(args, "--store") || "all" print_result(client.storage_delete(page, stores: store)) end |
.run_export(client, args) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/browserctl/commands/storage.rb', line 39 def self.run_export(client, args) page = args.shift or abort "usage: browserctl storage export <page> <path> [--store local|session|all]" path = args.shift or abort "usage: browserctl storage export <page> <path> [--store local|session|all]" store = extract_opt(args, "--store") || "all" print_result(client.storage_export(page, path, stores: store)) end |
.run_get(client, args) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/browserctl/commands/storage.rb', line 24 def self.run_get(client, args) page = args.shift or abort "usage: browserctl storage get <page> <key> [--store local|session]" key = args.shift or abort "usage: browserctl storage get <page> <key> [--store local|session]" store = extract_opt(args, "--store") || "local" print_result(client.storage_get(page, key, store: store)) end |
.run_import(client, args) ⇒ Object
46 47 48 49 50 |
# File 'lib/browserctl/commands/storage.rb', line 46 def self.run_import(client, args) page = args.shift or abort "usage: browserctl storage import <page> <path>" path = args.shift or abort "usage: browserctl storage import <page> <path>" print_result(client.storage_import(page, path)) end |
.run_set(client, args) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/browserctl/commands/storage.rb', line 31 def self.run_set(client, args) page = args.shift or abort "usage: browserctl storage set <page> <key> <value> [--store local|session]" key = args.shift or abort "usage: browserctl storage set <page> <key> <value> [--store local|session]" value = args.shift or abort "usage: browserctl storage set <page> <key> <value> [--store local|session]" store = extract_opt(args, "--store") || "local" print_result(client.storage_set(page, key, value, store: store)) end |