Sha256: 10c9303d65f5a1f7f454c57f13f5b812bf324344f4d25be0f1dec74109f47806

Contents?: true

Size: 1.3 KB

Versions: 14

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path('../../../lib',__FILE__))

require 'command_kit/commands'

require_relative 'cli/config'
require_relative 'cli/list'
require_relative 'cli/update'

module Foo
  #
  # The main CLI command.
  #
  class CLI

    include CommandKit::Commands

    class << self
      # The global configuration file setting.
      #
      # @return [String, nil]
      attr_accessor :config_file
    end

    command_name 'foo'

    # Commands must be explicitly registered, unless
    # CommandKit::Commands::AutoLoad.new(...) is included.
    command Config
    command List
    command Update

    # Commands may have aliases
    command_aliases['ls'] = 'list'
    command_aliases['up'] = 'update'

    # Global options may be defined which are parsed before the sub-command's
    # options are parsed and the sub-command is executed.
    option :config_file, short: '-C',
                         value: {
                           type: String,
                           usage: 'FILE'
                         },
                         desc: 'Global option to set the config file' do |file|
                           CLI.config_file = file
                         end

  end
end

if $0 == __FILE__
  # Normally you would invoke Foo::CLI.start from a bin/ script.
  Foo::CLI.start
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
command_kit-0.6.0 examples/subcommands/cli.rb
command_kit-0.5.6 examples/subcommands/cli.rb
command_kit-completion-0.2.1 examples/cli.rb
command_kit-completion-0.2.0 examples/cli.rb
command_kit-0.5.5 examples/subcommands/cli.rb
command_kit-0.5.4 examples/subcommands/cli.rb
command_kit-0.5.3 examples/subcommands/cli.rb
command_kit-0.5.2 examples/subcommands/cli.rb
command_kit-0.5.1 examples/subcommands/cli.rb
command_kit-0.5.0 examples/subcommands/cli.rb
command_kit-0.4.1 examples/subcommands/cli.rb
command_kit-completion-0.1.2 examples/cli.rb
command_kit-completion-0.1.1 examples/cli.rb
command_kit-completion-0.1.0 examples/cli.rb