Class: EverboxClient::CLI

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

Constant Summary collapse

SUPPORTED_COMMANDS =
{
  "login"     => "login",
  "ls"        => "list files and directories",
  "lsdir"     => "list directories",
  "get"       => "download file",
  "put"       => "upload file",
  "prepare_put" => "prepare put",
  "cd"        => "change dir",
  "pwd"       => "print working dir",
  "mkdir"     => "make directory",
  "rm"        => "delete file or directory",
  "mirror"    => "download dir",
  "info"      => "show user info",
  "config"       => "set config",
  "cat"       => "cat file",
  "help"       => "print help info",
  "thumbnail" => "get thumbnail url"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



36
37
38
39
40
41
42
43
# File 'lib/everbox_client/cli.rb', line 36

def initialize
  @options = {}

  # don't dump a backtrace on a ^C
  trap(:INT) {
    exit
  }
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



28
29
30
# File 'lib/everbox_client/cli.rb', line 28

def command
  @command
end

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/everbox_client/cli.rb', line 29

def options
  @options
end

#stdinObject (readonly)

Returns the value of attribute stdin.



30
31
32
# File 'lib/everbox_client/cli.rb', line 30

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



30
31
32
# File 'lib/everbox_client/cli.rb', line 30

def stdout
  @stdout
end

Class Method Details

.execute(stdout, stdin, stderr, arguments = []) ⇒ Object



32
33
34
# File 'lib/everbox_client/cli.rb', line 32

def self.execute(stdout, stdin, stderr, arguments = [])
  self.new.execute(stdout, stdin, stderr, arguments)
end

Instance Method Details

#execute(stdout, stdin, stderr, arguments = []) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/everbox_client/cli.rb', line 45

def execute(stdout, stdin, stderr, arguments = [])
  @stdout = stdout
  @stdin  = stdin
  @stderr = stderr
  extract_command_and_parse_options(arguments)
  parse_env

  if valid_command?
    begin
      runner = EverboxClient::Runner.new @opts
      runner.send @command, *@args
      runner.dump_config
    rescue => e
      raise e
      STDERR.write "Error: #{e.message}\n"
      exit 1
    end
  else
    usage
  end
end