Module: Duse::CLI

Extended by:
CLI
Included in:
CLI
Defined in:
lib/duse/cli.rb,
lib/duse/cli/help.rb,
lib/duse/cli/login.rb,
lib/duse/cli/config.rb,
lib/duse/cli/parser.rb,
lib/duse/cli/secret.rb,
lib/duse/cli/account.rb,
lib/duse/cli/command.rb,
lib/duse/cli/version.rb,
lib/duse/cli/register.rb,
lib/duse/cli/secret_add.rb,
lib/duse/cli/secret_get.rb,
lib/duse/cli/api_command.rb,
lib/duse/cli/secret_list.rb,
lib/duse/cli/account_info.rb,
lib/duse/cli/meta_command.rb,
lib/duse/cli/secret_remove.rb,
lib/duse/cli/secret_update.rb,
lib/duse/cli/account_update.rb,
lib/duse/cli/account_confirm.rb,
lib/duse/cli/share_with_user.rb,
lib/duse/cli/account_password.rb,
lib/duse/cli/account_password_reset.rb,
lib/duse/cli/account_password_change.rb,
lib/duse/cli/account_resend_confirmation.rb

Defined Under Namespace

Modules: Parser, ShareWithUser Classes: Account, AccountConfirm, AccountInfo, AccountPassword, AccountPasswordChange, AccountPasswordReset, AccountResendConfirmation, AccountUpdate, ApiCommand, Command, Config, Help, Login, MetaCommand, Register, Secret, SecretAdd, SecretGet, SecretList, SecretRemove, SecretUpdate, Version

Instance Method Summary collapse

Instance Method Details

#command(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/duse/cli.rb', line 28

def command(args)
  name = args.shift unless args.empty?
  const_name = command_name(name)
  constant   = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/ and const_defined? const_name
  if command? constant
    command = constant
    return deep_subcommand(command, args)
  end
  $stderr.puts "unknown command #{name}"
  exit 1
end

#commandsObject



47
48
49
# File 'lib/duse/cli.rb', line 47

def commands
  CLI.constants.map { |n| try_const_get(n) }.select { |c| command? c }
end

#configObject



60
61
62
# File 'lib/duse/cli.rb', line 60

def config
  Duse.config ||= CLIConfig.new(CLIConfig.load)
end

#config=(config) ⇒ Object



64
65
66
# File 'lib/duse/cli.rb', line 64

def config=(config)
  Duse.config = config
end

#deep_subcommand(command, args) ⇒ Object



40
41
42
43
44
45
# File 'lib/duse/cli.rb', line 40

def deep_subcommand(command, args)
  loop do
    return command unless command.subcommand args.first
    command = command.subcommand args.shift
  end
end

#run(*args) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/duse/cli.rb', line 20

def run(*args)
  args, opts = preparse(args)
  command_class = command(args)
  command = command_class.new(opts)
  command.parse(args)
  command.execute
end

#silentObject



51
52
53
54
55
56
57
58
# File 'lib/duse/cli.rb', line 51

def silent
  stderr, $stderr = $stderr, dummy_io
  stdout, $stdout = $stdout, dummy_io
  yield
ensure
  $stderr = stderr if stderr
  $stdout = stdout if stdout
end