Method: FeatureMap::Cli.for_file
- Defined in:
- lib/feature_map/cli.rb
.for_file(argv) ⇒ Object
For now, this just returns feature assignment Later, this could also return feature assignment errors about that file.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/feature_map/cli.rb', line 272 def self.for_file(argv) = {} # Long-term, we probably want to use something like `thor` so we don't have to implement logic # like this. In the short-term, this is a simple way for us to use the built-in OptionParser # while having an ergonomic CLI. files = argv.reject { |arg| arg.start_with?('--') } parser = OptionParser.new do |opts| opts. = 'Usage: bin/featuremap for_file [options]' opts.on('--json', 'Output as JSON') do [:json] = true end opts.on('--help', 'Shows this prompt') do puts opts exit end end args = parser.order!(argv) parser.parse!(args) if files.count != 1 raise 'Please pass in one file. Use `bin/featuremap for_file --help` for more info' end feature = FeatureMap.for_file(files.first) feature_name = feature&.name || 'Unassigned' feature_yml = feature&.config_yml || 'Unassigned' if [:json] json = { feature_name: feature_name, feature_yml: feature_yml } puts json.to_json else puts " Feature: \#{feature_name}\n Feature YML: \#{feature_yml}\n MSG\n end\nend\n" |