Class: Inmake::Config
- Inherits:
-
Object
- Object
- Inmake::Config
- Defined in:
- lib/inmake/config.rb
Overview
Stores inmake configuration options.
Instance Attribute Summary collapse
-
#dirMode ⇒ Object
readonly
Returns the value of attribute dirMode.
-
#files ⇒ Object
Returns the value of attribute files.
-
#ignoreNonmatches ⇒ Object
readonly
Returns the value of attribute ignoreNonmatches.
-
#searchArgument ⇒ Object
readonly
Returns the value of attribute searchArgument.
-
#searchMode ⇒ Object
readonly
Returns the value of attribute searchMode.
-
#stripMatched ⇒ Object
readonly
Returns the value of attribute stripMatched.
-
#variables ⇒ Object
Returns the value of attribute variables.
-
#variablesDisabled ⇒ Object
readonly
Returns the value of attribute variablesDisabled.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(opts) ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/inmake/config.rb', line 12 def initialize opts # How we treat directories that have been passed to the file list. # Possible values are :acceptDirs, :ignoreDirs # :acceptDirs => directories are accepted and recursed into # :ignoreDirs => directories are ignored @dirMode = opts[:dirMode] # A list of all the files that inmake will act on. # This may include directories or relative paths. @files = opts[:files] # How inmake looks for the build command inside the file. Possible values # are :prefix, :suffix, :regex, :secondLine # :prefix => search each line start for a prefix # :suffix => search each line ending for a suffix # :regex => search each line via an actual regex # :secondLine => use the second line (or third if the second looks like an # encoding line like Python) @searchMode = opts[:searchMode] # An additional argument to specify the thing that the search mode uses # to look for the build command. AKA, the actual prefix string or suffix # string or the regex object. @searchArgument = opts[:searchArgument] # Do we strip all found parts of the regex from the build command? @stripMatched = opts[:stripMatched] # Hash of variables that can be replaced in the build command @variables = opts[:variables] # Are variables disabled overall? Even the builtins that is... @variablesDisabled = opts[:variablesDisabled] # Do we stop when a file didn't have a command inside? @ignoreNonmatches = opts[:ignoreNonmatches] end |
Instance Attribute Details
#dirMode ⇒ Object (readonly)
Returns the value of attribute dirMode.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def dirMode @dirMode end |
#files ⇒ Object
Returns the value of attribute files.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def files @files end |
#ignoreNonmatches ⇒ Object (readonly)
Returns the value of attribute ignoreNonmatches.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def ignoreNonmatches @ignoreNonmatches end |
#searchArgument ⇒ Object (readonly)
Returns the value of attribute searchArgument.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def searchArgument @searchArgument end |
#searchMode ⇒ Object (readonly)
Returns the value of attribute searchMode.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def searchMode @searchMode end |
#stripMatched ⇒ Object (readonly)
Returns the value of attribute stripMatched.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def stripMatched @stripMatched end |
#variables ⇒ Object
Returns the value of attribute variables.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def variables @variables end |
#variablesDisabled ⇒ Object (readonly)
Returns the value of attribute variablesDisabled.
9 10 11 |
# File 'lib/inmake/config.rb', line 9 def variablesDisabled @variablesDisabled end |
Class Method Details
.fromArguments ⇒ Object
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/inmake/config.rb', line 43 def self.fromArguments require 'optparse' opts = {} opts[:files] = [] opts[:variables] = {} # Parse special arguments OptionParser.new do |parser| parser. = INMAKE_BANNER parser.on('-f', '--file FILENAME', 'Specify a target file.') do |filename| opts[:files] << filename end parser.on('-p', '--prefix PREFIX', 'Find the build command by a prefix.') do |prefix| unless opts[:searchMode] opts[:searchMode] = :prefix opts[:searchArgument] = prefix else raise MultipleModeException, "Multiple search mode definitions!" end end parser.on('-s', '--suffix SUFFIX', 'Find the build command by a suffix.') do |suffix| unless opts[:searchMode] opts[:searchMode] = :suffix opts[:searchArgument] = suffix else raise MultipleModeException, "Multiple search mode definitions!" end end okDirModes = [:acceptDirs, :ignoreDirs] parser.on('-d', '--dir-mode MODE', "Define behavior when dealing with a directory. (default: acceptDirs) Accepted values are: #{okDirModes.join ', '}") do |dm| dm = dm.to_sym raise InvalidDirMode, "Not a valid directory mode: #{dm}" unless okDirModes.include? dm opts[:dirMode] = dm end parser.on('-x', '--regex REGEX', 'Specify a regular expression to match the build command.') do |rx| unless opts[:searchMode] re = Regexp.compile rx opts[:searchMode] = :regex opts[:searchArgument] = re else raise MultipleModeException, "Multiple search mode definitions!" end end parser.on('--[no-]strip-matched', 'Strip all found matches on a regex search (default: false)') do |f| opts[:stripMatched] = f end parser.on('--[no-]ignore-nonmatched', 'Silently continue if a file does not seem to have a build command (default: true)') do |f| opts[:ignoreNonmatches] = f end parser.on('--no-vars', 'Disable all replacement variables, even the builtin ones (default: false)') do |v| opts[:variablesDisabled] = v end parser.on('-a', '--add-var KEY=VALUE', 'Add a replacement from {{KEY}} (always allcaps!) to VALUE, much like a C preprocessor definition') do |var| key, value = var.split '=' raise InvalidVarDefinition, "Invalid variable definition syntax: `#{var}`" unless key and value opts[:variables][key.upcase] = value end end.parse! # any arguments that weren't flags are just treated as file names unless ARGV.empty? opts[:files].concat ARGV end # The default search mode is to find the build command on the second line of # the source code. opts[:searchMode] ||= :secondLine # The default file mode means that if a directory is encountered, we recurse # on all its files. opts[:dirMode] ||= :acceptDirs # Variables are enabled by default. opts[:variablesDisabled] ||= false # By default, we do not strip the matched string. opts[:stripMatched] ||= false opts[:ignoreNonmatched] = true unless defined? opts[:ignoreNonmatched] # Can't run without ANY files... raise NoFilesGiven, "No input files specified! Use #{$0} --help for how to add input files." if opts[:files].empty? # return a new Config object return Config.new opts end |
.resolveFiles(cfg) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/inmake/config.rb', line 144 def self.resolveFiles cfg newFiles = [] cfg.files.each do |f| if File.exist? f if File.file? f newFiles << f elsif File.directory? f and cfg.dirMode == :acceptDirs newFiles.concat Dir[File.join(f, '**/*.*')].select {|x| File.file? x } end end end cfg.files = newFiles.map { |x| File. x } cfg end |