Module: BaseChip::Cli

Included in:
GeneratorMenu, InstallMenu, ListMenu, TopMenu
Defined in:
lib/base_chip/cli.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: Data, Task, TaskOrData

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
101
102
103
104
# File 'lib/base_chip/cli.rb', line 44

def self.included mod
  mod.extend Cli::ClassMethods
  mod.class_eval do
    include BaseChip::Reporting
    include Cli::InstanceMethods

    @cli    = Cli::Data.new

    desc    "Show usage information"
    example ""
    example " #{cli.tasks[1]}" if cli.tasks[1]
    def help(command = nil,*subcommands)
      puts ''
      if command 
        command = command.to_sym
        if (sc = cli.sub_commands[command])
          sc.new.help(*subcommands)
          return
        elsif t_cli = cli.tasks[command]
          puts "#{cli.full_command(command)} #{t_cli.usage}:"
        else
          fault "could not find help topic \"#{command}\""
        end
      else
        t_cli = cli

        puts "#{cli.full_command(command,false)}: "
      end

      if t_cli.description
        puts ''
        puts "    #{t_cli.description}"
      end
      if t_cli.long_description
        puts ''
        puts "    #{t_cli.long_description}"
      end
      
      unless command
        array = []
        cli.tasks.each_value do |t|
          if t.full_usage 
            array << [t.full_usage                                 ,t.description]
          else
            array << ["#{cli.full_command(t.name.to_s)} #{t.usage}",t.description]
          end
        end
        cli.sub_commands.each do |name,sc|
          array << ["#{sc.cli.full_command(nil,'false')} #{name} ...",sc.cli.description]
        end
        puts ''
        puts "    Commands:"
        cli.table(array,nil,"        ")

      end

      t_cli.options_table
      puts ''
    end
  end
end