Class: Bake::BakeryOptions
- Defined in:
- lib/bakery/options/options.rb
Instance Attribute Summary collapse
-
#collection_dir ⇒ Object
readonly
String.
-
#collection_name ⇒ Object
readonly
String.
-
#color ⇒ Object
readonly
Boolean.
-
#error ⇒ Object
readonly
Boolean.
-
#roots ⇒ Object
readonly
String List.
-
#socket ⇒ Object
readonly
Fixnum.
Instance Method Summary collapse
- #check_valid_dir(dir) ⇒ Object
-
#initialize(argv) ⇒ BakeryOptions
constructor
A new instance of BakeryOptions.
- #parse_options ⇒ Object
- #set_collection_dir(dir) ⇒ Object
- #set_collection_name(collection_name) ⇒ Object
- #set_root(dir) ⇒ Object
- #usage ⇒ Object
Methods inherited from Parser
#add_default, #add_option, #parse_internal
Constructor Details
#initialize(argv) ⇒ BakeryOptions
Returns a new instance of BakeryOptions.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bakery/options/options.rb', line 12 def initialize(argv) super(argv) @collection_name = "" @collection_dir = nil @color = nil @error = false @roots = [] @socket = 0 @def_roots = [] add_option(Option.new("-b",true) { |x| set_collection_name(x) }) add_option(Option.new("-m",true) { |x| set_collection_dir(x) }) add_option(Option.new("-r",false) { @error = true }) add_option(Option.new("-a",true) { |x|Bake.formatter.setColorScheme(x.to_sym) }) add_option(Option.new("-w",true) { |x| set_root(x) }) add_option(Option.new("--socket",true) { |x| @socket = String === x ? x.to_i : x }) add_option(Option.new("-h",false) { usage; ExitHelper.exit(0) }) end |
Instance Attribute Details
#collection_dir ⇒ Object (readonly)
String
7 8 9 |
# File 'lib/bakery/options/options.rb', line 7 def collection_dir @collection_dir end |
#collection_name ⇒ Object (readonly)
String
7 8 9 |
# File 'lib/bakery/options/options.rb', line 7 def collection_name @collection_name end |
#color ⇒ Object (readonly)
Boolean
9 10 11 |
# File 'lib/bakery/options/options.rb', line 9 def color @color end |
#error ⇒ Object (readonly)
Boolean
9 10 11 |
# File 'lib/bakery/options/options.rb', line 9 def error @error end |
#roots ⇒ Object (readonly)
String List
8 9 10 |
# File 'lib/bakery/options/options.rb', line 8 def roots @roots end |
#socket ⇒ Object (readonly)
Fixnum
10 11 12 |
# File 'lib/bakery/options/options.rb', line 10 def socket @socket end |
Instance Method Details
#check_valid_dir(dir) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bakery/options/options.rb', line 53 def check_valid_dir(dir) if not File.exists?(dir) Bake.formatter.printError("Error: Directory #{dir} does not exist") ExitHelper.exit(1) end if not File.directory?(dir) Bake.formatter.printError("Error: #{dir} is not a directory") ExitHelper.exit(1) end end |
#parse_options ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/bakery/options/options.rb', line 45 def () parse_internal(true) set_collection_dir(Dir.pwd) if @collection_dir.nil? if @roots.length == 0 @roots = @def_roots end end |
#set_collection_dir(dir) ⇒ Object
72 73 74 75 76 |
# File 'lib/bakery/options/options.rb', line 72 def set_collection_dir(dir) check_valid_dir(dir) @collection_dir = File.(dir.gsub(/[\\]/,'/')) @def_roots = calc_def_roots(@collection_dir) end |
#set_collection_name(collection_name) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/bakery/options/options.rb', line 64 def set_collection_name(collection_name) if not @collection_name.empty? Bake.formatter.printError("Error: Cannot set collection name '#{collection_name}', because collection name is already set to '#{@collection_name}'") ExitHelper.exit(1) end @collection_name = collection_name end |
#set_root(dir) ⇒ Object
78 79 80 81 82 |
# File 'lib/bakery/options/options.rb', line 78 def set_root(dir) check_valid_dir(dir) r = File.(dir.gsub(/[\\]/,'/')) @roots << r if not @roots.include?r end |
#usage ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bakery/options/options.rb', line 32 def usage puts "\nUsage: bake <name> [options]" puts " -b <name> Name of the collection to build." puts " -m <dir> Directory containing the collection file (default is current directory)." puts " -r Stop on first error." puts " -a <scheme> Use ansi color sequences (console must support it). Possible values are 'white' and 'black'." puts " -h Print this help." puts " -w <root> Add a workspace root (can be used multiple times)." puts " If no root is specified, the parent directory of Collection.meta is added automatically." puts " --socket <num> Set socket for sending errors, receiving commands, etc. - used by e.g. Eclipse." puts "Note: all parameters except -b, -m and -h will be passed to bake - see bake help for more options." end |