The project is in a healthy, maintained state
command_mapper-gen parses a command's --help output and man-page, then generates the command_mapper Ruby class for the command.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Development

~> 2.0

Runtime

~> 2.0
 Project Readme

command_mapper-gen

CI Gem Version

Description

command_mapper-gen parses a command's --help output and man-page and generates the command_mapper Ruby class for the command.

Features

  • Parses --help output.
  • Parses man pages.
  • Provides the command_mapper-gen command.
  • Provides a Rake task.

Synopsis

$ command_mapper-gen grep

Outputs:

Failed to parse line in `grep --help`:

    -NUM                      same as --context=NUM

Failed to match sequence (('	' / SPACES) OPTION ','? ([ \\t]{1, } OPTION_SUMMARY)? !.) at line 1 char 5.

require 'command_mapper/command'

#
# Represents the `grep` command
#
class Grep < CommandMapper::Command

  command "grep" do
    option "--extended-regexp"
    option "--fixed-strings"
    option "--basic-regexp"
    option "--perl-regexp"
    option "--regexp", equals: true, value: true
    option "--file", equals: true, value: true
    option "--ignore-case"
    option "--no-ignore-case"
    option "--word-regexp"
    option "--line-regexp"
    option "--null-data"
    option "--no-messages"
    option "--invert-match"
    option "--version"
    option "--help"
    option "--max-count", equals: true, value: {type: Num.new}
    option "--byte-offset"
    option "--line-number"
    option "--line-buffered"
    option "--with-filename"
    option "--no-filename"
    option "--label", equals: true, value: true
    option "--only-matching"
    option "--quiet"
    option "--binary-files", equals: true, value: true
    option "--text"
    option "-I", name: 	# FIXME: name
    option "--directories", equals: true, value: true
    option "--devices", equals: true, value: true
    option "--recursive"
    option "--dereference-recursive"
    option "--include", equals: true, value: true
    option "--exclude", equals: true, value: true
    option "--exclude-from", equals: true, value: true
    option "--exclude-dir", equals: true, value: true
    option "--files-without-match", value: true
    option "--files-with-matches"
    option "--count"
    option "--initial-tab"
    option "--null"
    option "--before-context", equals: true, value: {type: Num.new}
    option "--after-context", equals: true, value: {type: Num.new}
    option "--context", equals: true, value: {type: Num.new}
    option "--group-separator", equals: true, value: true
    option "--no-group-separator"
    option "--color", equals: :optional, value: {required: false}
    option "--colour", equals: :optional, value: {required: false}
    option "--binary"

    argument :patterns
    argument :file, required: false, repeats: true
  end

end

Output can also be written to a file:

$ command_mapper-gen -o lib/path/to/grep.rb grep

Examples

Rake Task

In Rakefile:

require 'command_mapper/gen/task'
CommandMapper::Gen::Task.new('grep','lib/path/to/grep.rb')

Requirements

Install

$ gem install command_mapper-gen

Gemfile

group :development do
  # ...

  gem 'command_mapper-gen', '~> 0.1', require: false
end

License

Copyright (c) 2021 Hal Brodigan

See {file:LICENSE.txt} for license information.