Class: OptionsStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- OptionsStruct
- Defined in:
- lib/railroady/options_struct.rb
Overview
RailRoady command line options parser
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ OptionsStruct
constructor
A new instance of OptionsStruct.
-
#parse(args) ⇒ Object
initialize.
Constructor Details
#initialize(args = {}) ⇒ OptionsStruct
Returns a new instance of OptionsStruct.
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 42 43 |
# File 'lib/railroady/options_struct.rb', line 13 def initialize(args = {}) = { all: false, brief: false, specify: [], exclude: [], inheritance: false, join: false, label: false, modules: false, all_columns: false, hide_magic: false, hide_types: false, hide_public: false, hide_protected: false, hide_private: false, plugins_models: false, engine_models: false, engine_controllers: false, include_concerns: false, root: '', show_belongs_to: false, hide_through: false, transitive: false, verbose: false, alphabetize: false, xmi: false, command: '', config_file: 'config/environment', app_name: 'railroady', app_human_name: 'Railroady', app_version: '', copyright: '' } super(.merge(args)) end |
Instance Method Details
#parse(args) ⇒ Object
initialize
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/railroady/options_struct.rb', line 45 def parse(args) @opt_parser = OptionParser.new do |opts| opts. = "Usage: #{app_name} [options] command" opts.separator '' opts.separator 'Common options:' opts.on('-b', '--brief', 'Generate compact diagram', ' (no attributes nor methods)') do |b| self.brief = b end opts.on('-s', '--specify file1[,fileN]', Array, 'Specify only given files') do |list| self.specify = list end opts.on('-e', '--exclude file1[,fileN]', Array, 'Exclude given files') do |list| self.exclude = list end opts.on('-i', '--inheritance', 'Include inheritance relations') do |i| self.inheritance = i end opts.on('-l', '--label', 'Add a label with diagram information', ' (type, date, migration, version)') do |l| self.label = l end opts.on('-o', '--output FILE', 'Write diagram to file FILE') do |f| self.output = f end opts.on('-r', '--root PATH', 'Set PATH as the application root') do |r| self.root = r end opts.on('-v', '--verbose', 'Enable verbose output', ' (produce messages to STDOUT)') do |v| self.verbose = v end opts.on('-x', '--xmi', 'Produce XMI instead of DOT', ' (for UML tools)') do |x| self.xmi = x end opts.on('--alphabetize', 'Sort methods alphabetically') do |a| self.alphabetize = a end opts.separator '' opts.separator 'Models diagram options:' opts.on('-a', '--all', 'Include all models', ' (not only ActiveRecord::Base derived)') do |a| self.all = a end opts.on('--show-belongs_to', 'Show belongs_to associations') do |s| self.show_belongs_to = s end opts.on('--hide-through', 'Hide through associations') do |h| self.hide_through = h end opts.on('--all-columns', 'Show all columns (not just content columns)') do |h| self.all_columns = h end opts.on('--hide-magic', 'Hide magic field names') do |h| self.hide_magic = h end opts.on('--hide-types', 'Hide attributes type') do |h| self.hide_types = h end opts.on('-j', '--join', 'Concentrate edges') do |j| self.join = j end opts.on('-m', '--modules', 'Include modules') do |m| self.modules = m end opts.on('-p', '--plugins-models', 'Include plugins models') do |p| self.plugins_models = p end opts.on('-z', '--engine-models', 'Include engine models') do |em| self.engine_models = em end opts.on('--include-concerns', 'Include models in concerns subdirectory') do |c| self.include_concerns = c end opts.on('-t', '--transitive', 'Include transitive associations', '(through inheritance)') do |t| self.transitive = t end opts.separator '' opts.separator 'Controllers diagram options:' opts.on('--hide-public', 'Hide public methods') do |h| self.hide_public = h end opts.on('--hide-protected', 'Hide protected methods') do |h| self.hide_protected = h end opts.on('--hide-private', 'Hide private methods') do |h| self.hide_private = h end opts.on('--engine-controllers', 'Include engine controllers') do |ec| self.engine_controllers = ec end opts.separator '' opts.separator 'Other options:' opts.on('-h', '--help', 'Show this message') do STDOUT.print "#{opts}\n" exit end opts.on('--version', 'Show version and copyright') do STDOUT.print "#{app_human_name} version #{app_version}\n\n" \ "#{copyright}\nThis is free software; see the source " \ "for copying conditions.\n\n" exit end opts.separator '' opts.on('-c', '--config FILE', 'File to load environment (defaults to config/environment)') do |c| self.config_file = c if c && c != '' end opts.separator 'Commands (you must supply one of these):' opts.on('-M', '--models', 'Generate models diagram') do |_c| if command != '' STDERR.print "Error: Can only generate one diagram type\n\n" exit 1 else self.command = 'models' end end opts.on('-C', '--controllers', 'Generate controllers diagram') do |_c| if command != '' STDERR.print "Error: Can only generate one diagram type\n\n" exit 1 else self.command = 'controllers' end end # From Ana Nelson's patch opts.on('-A', '--aasm', "Generate \"acts as state machine\" diagram") do |_c| if command == 'controllers' STDERR.print "Error: Can only generate one diagram type\n\n" exit 1 else self.command = 'aasm' end end opts.separator '' opts.separator 'For bug reporting and additional information, please see:' opts.separator 'http://railroad.rubyforge.org/' end # do begin @opt_parser.parse!(args) rescue OptionParser::AmbiguousOption option_error 'Ambiguous option' rescue OptionParser::InvalidOption option_error 'Invalid option' rescue OptionParser::InvalidArgument option_error 'Invalid argument' rescue OptionParser::MissingArgument option_error 'Missing argument' end end |