Class: BuildTool::Commands::Modules::List

Inherits:
Standard show all
Defined in:
lib/build-tool/commands/modules/list.rb

Overview

BuildCommand

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from Standard

#complete_module, #complete_modules, #initialize, #log_directory, #while_logging_to

Methods inherited from Base

#<=>, #applicable?, #cleanup_after_vcs_access, #complete_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #each_option, #error, #execute, #fullname, #info, #initialize, #log?, #quiet, #setup_command, #setup_options, #show_help, #skip_command, #summarize, #teardown_command, #trace, #usage, #verbose, #warn

Methods included from HelpText

#cmdalias, #description, included, #long_description, #name

Constructor Details

This class inherits a constructor from BuildTool::Commands::Standard

Instance Method Details

#do_execute(args) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/build-tool/commands/modules/list.rb', line 94

def do_execute( args )
    # *TODO* listing local and remote recipes
    if args.length == 0
        show_modules( configuration.modules )
    else
        args.each do |arg|
            mods = complete_modules( arg, @template )
            next if !mods
            show_modules( mods )
        end
    end

    return 0
end

#ensure_option_not_set(option, name, conflicts) ⇒ Object



31
32
33
34
35
# File 'lib/build-tool/commands/modules/list.rb', line 31

def ensure_option_not_set( option, name, conflicts )
    if option
        raise UsageError, "Options --#{conflicts} and --#{name} are mutually exclusive."
    end
end

#initialize_optionsObject



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
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
# File 'lib/build-tool/commands/modules/list.rb', line 37

def initialize_options
    options.banner = "Usage: #{self.fullname} [OPTIONS]... [MODULE|GROUP]..."
    options.separator( "" )
    options.separator( "Options" )

    @all = false

    options.separator( '' )
    options.separator( '  Criterias' )

    @active = true
    @inactive = false
    options.on( "--all", "Include inactive modules." ) {
        ensure_option_not_set( @disabled, 'disabled', 'all' )
        ensure_option_not_set( @broken, 'broken', 'all' )
        @all = true
        @active = true
        @inactive = true
        }

    options.on( "--disabled", "Only show inactive modules." ) {
        ensure_option_not_set( @all, 'all', 'disabled' )
        ensure_option_not_set( @broken, 'broken', 'disabled' )
        @active = false
        @inactive = true
        }

    @template = false
    options.on( "--template", "Include template modules." ) {
        @template = true
        }

    @broken = false
    options.on( "--broken", "Show only broken modules." ) {
        ensure_option_not_set( @all, 'all', 'broken' )
        ensure_option_not_set( @disabled, 'disabled', 'broken' )
        @broken = true
        }

    options.separator( '' )
    options.separator( '  Sort order' )

    @outdated = false
    options.on( "--outdated", "Show modules sorted by date of last successful compile." ) {
        ensure_option_not_set( !@sort, 'no-sort', 'outdated' )
        @outdated = true
        }

    @sort = true
    options.on( "--no-sort", "Show modules in order of declaration." ) {
        ensure_option_not_set( @outdated, 'outdated', 'no-sort' )
        @sort = false
        }

    super
end

#show_module(mod) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/build-tool/commands/modules/list.rb', line 117

def show_module( mod )
    return if @broken         and not mod.broken?
    if mod.active?
        return if not @active
    else
        return if not @inactive
    end
    return if mod.is_template?   and not @template

    if @broken
        info( "%s%s %-35s : %-25s" % [ mod.active_char, mod.state_char, mod.name, mod.state ] )
    elsif @outdated
        if mod.last_success == DateTime.new
            success = 'unknown'
        else
            success =  mod.last_success.strftime("%x %X")
        end
        info( "%s%s %-35s : %s" % [ mod.active_char, mod.state_char, mod.name, success ] )
    else
        info( "%s%s %-35s : %s" % [ mod.active_char, mod.state_char, mod.name, mod.description || "No description specified" ] )
    end
end

#show_modules(mods) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/build-tool/commands/modules/list.rb', line 109

def show_modules( mods )
    mods = mods.sort if @sort
    mods = mods.sort { |x, y| x.last_success <=> y.last_success }.reverse if @outdated
    mods.each do |mod|
        show_module( mod )
    end
end