Class: Sem4rCli::CommandProfile

Inherits:
OptParseCommand::Command
  • Object
show all
Defined in:
lib/sem4r_cli/commands/cmd_profile.rb

Overview

Manage Sem4r profiles

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commandObject



34
35
36
# File 'lib/sem4r_cli/commands/cmd_profile.rb', line 34

def self.command
  "profile"
end

.descriptionObject



38
39
40
# File 'lib/sem4r_cli/commands/cmd_profile.rb', line 38

def self.description
  "manage sem4r profiles (subcommands: #{sub_commands.join(', ')})"
end

.sub_commandsObject



46
47
48
# File 'lib/sem4r_cli/commands/cmd_profile.rb', line 46

def self.sub_commands
  %w{list create}
end

.usageObject



42
43
44
# File 'lib/sem4r_cli/commands/cmd_profile.rb', line 42

def self.usage
  "usage profile"
end

Instance Method Details

#exec(sem4r_cli, options, rest) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sem4r_cli/commands/cmd_profile.rb', line 62

def exec(sem4r_cli, options, rest)
  options = OpenStruct.new
  rest    = command_opt_parser(options).parse(rest)
  return false if options.exit
  if rest.empty?
    # puts "missing command"
    # return false
    rest << "list" # default command
  end

  ret             = true
  sub_command      = rest[0]
  sub_command_args = rest[1..-1]
  adwords         = sem4r_cli.adwords
  case sub_command
    when "list"
      puts "Profiles:"

      items    = []
      profiles = adwords.profiles
      names    = profiles.keys.map &:to_s
      names.sort.each do |s|
        o             = OpenStruct.new
        o.name        = s
        o.email       = profiles[s]['email']
        o.mutable     = profiles[s]['mutable']
        o.environment = profiles[s]['environment']
        items << o
      end
      OptParseCommand::report(items, :name, :environment, :email, :mutable)
    when "create"
      puts "Tobe done :-)"

    else
      puts "unknow command '#{sub_command}'; must be one of #{self.class.sub_commands.join(", ")}"
      return false
  end
  ret
end

#option_parser(options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/sem4r_cli/commands/cmd_profile.rb', line 51

def option_parser(options)
  opt_parser        = OptionParser.new
  opt_parser.banner = "Usage #{self.class.command} [command_options] [#{self.class.sub_commands.join("|")}]"
  opt_parser.separator ""
  opt_parser.separator "#{self.class.description}"
  opt_parser.on("-h", "--help", "show this message") do
    puts opt_parser
    options.exit = true
  end
end