Class: Texico::CLI::ArgParser
- Inherits:
-
Object
- Object
- Texico::CLI::ArgParser
- Defined in:
- lib/texico/cli/arg_parser.rb
Instance Method Summary collapse
-
#parse(items = ARGV, prompt: TTY::Prompt.new) ⇒ Object
Returns a hash with the options.
Instance Method Details
#parse(items = ARGV, prompt: TTY::Prompt.new) ⇒ Object
Returns a hash with the options
The method may call Kernel.exit
10 11 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/texico/cli/arg_parser.rb', line 10 def parse(items = ARGV, prompt: TTY::Prompt.new) title = prompt.decorate('texico', :yellow) opts = Slop.parse(items) do |o| o. = "#{title} [options] ..." o.bool '-v', '--verbose', 'enable verbose mode' o.bool '-q', '--quiet', 'suppress output (quiet mode)' o.bool '-h', '--help', 'Display this help' o.bool '-f', '--force', "Force #{title} to act" o.bool '-d', '--dry-run', 'Only show what files would be copied' o.string '-c', '--config', 'Config file to use', default: ConfigFile::DEFAULT_NAME o.on '--version', 'print the version' do puts VERSION exit end o.separator "\n#{title} [options] init [directory]" o.separator " Initializes a new #{ICON} project in the " \ "current directory." o.bool '--no-git', 'Do not initialize a new git repository' o.separator "\n#{title} [options] config [--global] KEY=VALUE" o.separator " Change configuration options." o.bool '-g', '--global', 'edit the global configuration' o.separator "\n#{title} [options] clean" o.separator " Remove all build files" o.separator "\n#{title} [options] release TAG_LABEL" o.separator " Build and tag the project" end if opts[:help] puts opts exit end command = opts.arguments[0] Command.match command, prompt, { cmd: command, args: opts.arguments[1..-1], title: title, **opts.to_hash } end |