~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/commands/groups.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# groups.rb: a group of commands
 
2
# copyright (c) 2009 by Vincent Fourmond
 
3
  
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
  
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details (in the COPYING file).
 
13
 
 
14
require 'ctioga2/utils'
 
15
require 'ctioga2/metabuilder/types'
 
16
 
 
17
module CTioga2
 
18
 
 
19
  Version::register_svn_info('$Revision: 14 $', '$Date: 2009-04-27 21:49:16 +0200 (Mon, 27 Apr 2009) $')
 
20
 
 
21
  module Commands
 
22
 
 
23
    # A group of commands, organized along a same theme.
 
24
    class CommandGroup
 
25
 
 
26
      # The commands belonging to the group
 
27
      attr_accessor :commands
 
28
 
 
29
      # The name of the group
 
30
      attr_accessor :name
 
31
 
 
32
      # A short, unique, codelike name for the group.
 
33
      attr_accessor :id
 
34
 
 
35
      # A (longer) description of the group
 
36
      attr_accessor :description
 
37
 
 
38
      # The priority of the group. It influences the positioning of
 
39
      # its command-line options in the --help display. Lower
 
40
      # priorities come first.
 
41
      attr_accessor :priority
 
42
 
 
43
      # Whether the group is blacklisted or not, ie whether the group's
 
44
      # help text will be displayed at all. 
 
45
      attr_accessor :blacklisted
 
46
 
 
47
      # The context of definition [file, line]
 
48
      attr_accessor :context
 
49
      
 
50
      def initialize(id, name, desc = nil, priority = 0, blacklist = false,
 
51
                     register = true)
 
52
        @commands = []
 
53
        @name = name
 
54
        @id = id
 
55
        @description = desc || name
 
56
        @priority = priority
 
57
        @blacklisted = blacklist
 
58
 
 
59
        if register 
 
60
          Interpreter.register_group(self)
 
61
        end
 
62
 
 
63
        # The context in which the group was defined
 
64
        caller[1].gsub(/.*\/ctioga2\//, 'lib/ctioga2/') =~ /(.*):(\d+)/
 
65
        @context = [$1, $2.to_i]
 
66
      end
 
67
      
 
68
    end
 
69
 
 
70
  end
 
71
 
 
72
end
 
73