Class: Spider::CommandLine::Cmd

Inherits:
Object
  • Object
show all
Defined in:
lib/spiderfw/cmd/cmd.rb

Instance Method Summary collapse

Constructor Details

#initializeCmd

Returns a new instance of Cmd.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spiderfw/cmd/cmd.rb', line 19

def initialize
    @cmd = CmdParse::CommandParser.new({:handle_exceptions => true, :takes_commands => true})
    @cmd.program_name = "spider"
    @cmd.options = CmdParse::OptionParserWrapper.new do |opt|
        opt.separator _("Global options:")
        opt.on("--version", _("Output Spider version and exit"), "-v"){ |v| 
            require 'spiderfw/version'
            puts Spider::VERSION
            exit
        }
        opt.on("--verbose", _("Be verbose when outputting info"), "-V" ) {|t| $verbose = true }
        opt.on("--chdir", _("Cd to a directory before running"), "-c"){ |c| Dir.chdir(c) }
        opt.on("--sets SETS", Array, _("Include configuration sets"), "-s"){ |sets|
            $SPIDER_CONFIG_SETS = sets
        }
        opt.on("--devel", _("Set runmode to devel"), "-d") do
            $SPIDER_RUNMODE = 'devel'
        end
        opt.on("--test", _("Set runmode to test")) do
            $SPIDER_RUNMODE = 'test'
        end
        opt.on("--http-proxy [PROXY]", _("Proxy server to use for http operations (http://user:pass@host:port)")){ |p|
            ENV['http_proxy'] = p
        }
    end

    @cmd.add_command(CmdParse::HelpCommand.new, true)
    @cmd.add_command(WebServerCommand.new)
    @cmd.add_command(CreateCommand.new)
    @cmd.add_command(ConsoleCommand.new)
    begin
        require 'spiderfw/cmd/commands/cert'
        @cmd.add_command(CertCommand.new)
    rescue LoadError
    end
    @cmd.add_command(TestCommand.new)
    @cmd.add_command(SetupCommand.new)
    @cmd.add_command(ModelCommand.new)
    @cmd.add_command(ConfigCommand.new)
    @cmd.add_command(ContentCommand.new)
    @cmd.add_command(AppCommand.new)
    # @cmd.add_command(ScaffoldCommand.new)
    @cmd.add_command(AssetsCommand.new)
end

Instance Method Details

#parseObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/spiderfw/cmd/cmd.rb', line 64

def parse
    cmd_name = nil
    0.upto(ARGV.length) do |i|
        if (ARGV[i] && ARGV[i] != 'help' && ARGV[i][0].chr != '-')
            cmd_name = ARGV[i]
            break
        end
    end
    cmd_name ||= 'help'
    if !@cmd.main_command.commands[cmd_name]
        $SPIDER_CMD = true
        require 'spiderfw/init'
        if Spider.apps_by_short_name[cmd_name] && Spider.apps_by_short_name[cmd_name].const_defined?(:Cmd)
            app_cmd = Spider.apps_by_short_name[cmd_name].const_get(:Cmd).new
            @cmd.add_command(app_cmd)
#                    app_cmd.add_command(CmdParse::HelpCommand.new, true)
        end
    end
    @cmd.parse
end