module UniversaTools::Commons::CliCommands

Public Instance Methods

cmd(name1, name2, description = nil, &block) click to toggle source
# File lib/universa_tools/commons.rb, line 83
def cmd(name1, name2, description = nil, &block)
  if !description
    description = name2
    name2 = nil
  end
  command = Command.new(name1, name2, description, block)
  @commands[name1] = command
  @commands[name2] = command if name2
end
cmd_list() click to toggle source
# File lib/universa_tools/commons.rb, line 93
def cmd_list
  puts "Listing contents of #@keyring_path:"
  keyring
end
init_commands() click to toggle source
# File lib/universa_tools/commons.rb, line 98
def init_commands
  cmd("help", "help on supported commands. To get extended help on some command, use 'help <command>'.") { |args|
    STDOUT.puts @option_parser.banner
    puts ""
    if args.empty?
      puts "#{ANSI.bold { "Available commands:" }}\n\n"
      cc = @commands.values.uniq
      first_column_size = cc.map { |x| x.name.size }.max + 2
      cc.each { |cmd|
        description_lines =
            first_spacer = ANSI.bold { ANSI.yellow { "%#{-first_column_size}s" % cmd.name } }
        next_spacer = ' ' * first_column_size
        cmd.description.word_wrap(@term_width - first_column_size).lines.each_with_index { |s, n|
          STDOUT << (n == 0 ? first_spacer : next_spacer)
          STDOUT.puts s
        }

      }
    else
      puts "-- not yet ready"
    end
  }

  cmd("list", "l", "show contents of the keyring")
end