Class: PagecordCLI::CLI
- Inherits:
-
Object
- Object
- PagecordCLI::CLI
- Defined in:
- lib/pagecord_cli/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(argv, config: Config.new, input: $stdin, output: $stdout, error: $stderr) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
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
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
8 9 10 |
# File 'lib/pagecord_cli/cli.rb', line 8 def argv @argv end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/pagecord_cli/cli.rb', line 8 def config @config end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/pagecord_cli/cli.rb', line 8 def error @error end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
8 9 10 |
# File 'lib/pagecord_cli/cli.rb', line 8 def input @input end |
#output ⇒ Object (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
#run ⇒ Object
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 login 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((e)) rescue Config::Error => e fail_with(e.) rescue Errno::ENOENT => e fail_with(e.) rescue Interrupt error.puts fail_with("Cancelled") end |