Module: Browserctl::Commands::Page

Extended by:
CliOutput
Defined in:
lib/browserctl/commands/page.rb

Constant Summary collapse

USAGE =
"Usage: browserctl page <open|close|list|focus|snapshot|screenshot> [args]"

Constants included from CliOutput

CliOutput::AUTH_REQUIRED_EXIT_CODE

Class Method Summary collapse

Methods included from CliOutput

exit_code_for, print_result, structured_error_line

Class Method Details

.run(client, args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/browserctl/commands/page.rb', line 15

def self.run(client, args)
  sub = args.shift or abort USAGE
  case sub
  when "open"       then run_open(client, args)
  when "close"      then run_close(client, args)
  when "list"       then run_list(client)
  when "focus"      then run_focus(client, args)
  when "snapshot"   then Browserctl::Commands::Snapshot.run(client, args)
  when "screenshot" then Browserctl::Commands::Screenshot.run(client, args)
  else abort "unknown page subcommand '#{sub}'\n#{USAGE}"
  end
end

.run_close(client, args) ⇒ Object



36
37
38
39
# File 'lib/browserctl/commands/page.rb', line 36

def self.run_close(client, args)
  name = args.shift or abort "usage: browserctl page close <name>"
  print_result(client.page_close(name))
end

.run_focus(client, args) ⇒ Object



45
46
47
48
# File 'lib/browserctl/commands/page.rb', line 45

def self.run_focus(client, args)
  name = args.shift or abort "usage: browserctl page focus <name>"
  print_result(client.page_focus(name))
end

.run_list(client) ⇒ Object



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

def self.run_list(client)
  print_result(client.page_list)
end

.run_open(client, args) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/browserctl/commands/page.rb', line 28

def self.run_open(client, args)
  opts = Optimist.options(args) do
    opt :url, "URL to navigate to", type: :string, short: "-u"
  end
  name = args.shift or abort "usage: browserctl page open <name> [--url URL]"
  print_result(client.page_open(name, url: opts[:url]))
end