Module: Browserctl::Commands::Cookie
- Extended by:
- CliOutput
- Defined in:
- lib/browserctl/commands/cookie.rb
Constant Summary
collapse
- USAGE =
"Usage: browserctl cookie <list|set|delete|export|import> [args]"
Constants included
from CliOutput
Browserctl::Commands::CliOutput::AUTH_REQUIRED_EXIT_CODE
Class Method Summary
collapse
Methods included from CliOutput
exit_code_for, print_result, structured_error_line
Class Method Details
.deprecation_replacement(sub) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/browserctl/commands/cookie.rb', line 30
def self.deprecation_replacement(sub)
case sub
when "list" then "data list <page> --scope cookies"
when "set" then "data set <page> <name> <value> --scope cookies --domain DOMAIN"
when "delete" then "data delete <page> --scope cookies"
when "export" then "data list <page> --scope cookies # write to file client-side"
when "import" then "data set <page> --scope cookies"
else "data <op> --scope cookies"
end
end
|
.run(client, args) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/browserctl/commands/cookie.rb', line 13
def self.run(client, args)
sub = args.shift or abort USAGE
DeprecationNotice.emit(
"cookie #{sub}",
deprecation_replacement(sub)
)
case sub
when "list" then run_list(client, args)
when "set" then run_set(client, args)
when "delete" then run_delete(client, args)
when "export" then run_export(client, args)
when "import" then run_import(client, args)
else abort "unknown cookie subcommand '#{sub}'\n#{USAGE}"
end
end
|
.run_delete(client, args) ⇒ Object
58
59
60
61
|
# File 'lib/browserctl/commands/cookie.rb', line 58
def self.run_delete(client, args)
page = args.shift or abort "usage: browserctl cookie delete <page>"
print_result(client.delete_cookies(page))
end
|
.run_export(client, args) ⇒ Object
63
64
65
66
67
|
# File 'lib/browserctl/commands/cookie.rb', line 63
def self.run_export(client, args)
page = args.shift or abort "usage: browserctl cookie export <page> <path>"
path = args.shift or abort "usage: browserctl cookie export <page> <path>"
print_result(client.export_cookies(page, path))
end
|
.run_import(client, args) ⇒ Object
69
70
71
72
73
|
# File 'lib/browserctl/commands/cookie.rb', line 69
def self.run_import(client, args)
page = args.shift or abort "usage: browserctl cookie import <page> <path>"
path = args.shift or abort "usage: browserctl cookie import <page> <path>"
print_result(client.import_cookies(page, path))
end
|
.run_list(client, args) ⇒ Object
41
42
43
44
|
# File 'lib/browserctl/commands/cookie.rb', line 41
def self.run_list(client, args)
page = args.shift or abort "usage: browserctl cookie list <page>"
print_result(client.cookies(page))
end
|
.run_set(client, args) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/browserctl/commands/cookie.rb', line 46
def self.run_set(client, args)
page = args.shift or abort "usage: browserctl cookie set <page> <name> <value> --domain DOMAIN [--path /]"
name = args.shift or abort "usage: browserctl cookie set <page> <name> <value> --domain DOMAIN [--path /]"
value = args.shift or abort "usage: browserctl cookie set <page> <name> <value> --domain DOMAIN [--path /]"
domain_idx = args.index("--domain")
domain = domain_idx ? args.delete_at(domain_idx + 1).tap { args.delete_at(domain_idx) } : nil
abort "usage: browserctl cookie set <page> <name> <value> --domain DOMAIN" unless domain
path_idx = args.index("--path")
path = path_idx ? args.delete_at(path_idx + 1).tap { args.delete_at(path_idx) } : "/"
print_result(client.set_cookie(page, name, value, domain, path: path))
end
|