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]"

Class Method Summary collapse

Methods included from CliOutput

print_result

Class Method Details

.run(client, args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/browserctl/commands/cookie.rb', line 12

def self.run(client, args)
  sub = args.shift or abort USAGE
  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



41
42
43
44
# File 'lib/browserctl/commands/cookie.rb', line 41

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



46
47
48
49
50
# File 'lib/browserctl/commands/cookie.rb', line 46

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



52
53
54
55
56
# File 'lib/browserctl/commands/cookie.rb', line 52

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



24
25
26
27
# File 'lib/browserctl/commands/cookie.rb', line 24

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



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/browserctl/commands/cookie.rb', line 29

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