Class: PagecordCLI::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pagecord_cli/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, config: Config.new, input: $stdin, output: $stdout, error: $stderr) ⇒ CLI

Returns a new instance of CLI.



10
11
12
13
14
15
16
# File 'lib/pagecord_cli/cli.rb', line 10

def initialize(argv, config: Config.new, input: $stdin, output: $stdout, error: $stderr)
  @argv = argv.dup
  @config = config
  @input = input
  @output = output
  @error = error
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



8
9
10
# File 'lib/pagecord_cli/cli.rb', line 8

def argv
  @argv
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/pagecord_cli/cli.rb', line 8

def config
  @config
end

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/pagecord_cli/cli.rb', line 8

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input.



8
9
10
# File 'lib/pagecord_cli/cli.rb', line 8

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/pagecord_cli/cli.rb', line 8

def output
  @output
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pagecord_cli/cli.rb', line 18

def run
  command = argv.shift

  case command
  when "login" then 
  when "logout" then logout
  when "list" then list
  when "publish" then publish("published")
  when "draft" then publish("draft")
  when "help", nil, "-h", "--help" then help
  else
    fail_with("Unknown command: #{command}")
  end
rescue Client::Error => e
  fail_with(api_error_message(e))
rescue Config::Error => e
  fail_with(e.message)
rescue Errno::ENOENT => e
  fail_with(e.message)
rescue Interrupt
  error.puts
  fail_with("Cancelled")
end