Sha256: 88dae35e0041c86091039c4718f666d6b477e95f87f820d26f842dddd6d688f7

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

# TODO: Yes, at some point this will be bootstrapped by exctl itself.

module Exctl
  def self.cli(argv) Exctl::CLI.new(argv).run! end

  class CLI
    def initialize(argv)
      @args = argv.clone
      @cmd = (@args.shift || 'help').strip.downcase
      @cmd = 'help'    if [nil,'-h','--help','h'].include?(@cmd)
      @cmd = 'version' if [nil,'-v','--version','v'].include?(@cmd)
      @cmd = ('cmd_' + @cmd.gsub(/^-+/,'').gsub('-','_')).to_sym
      @opts = {}
    end

    def run!()
      if self.respond_to?(@cmd) then self.send @cmd
      else
        $stderr.puts "ERROR: Command '#{@cmd}' not implemented."
        $stderr.puts "USAGE: exctl (#{avail_cmds.join('|')}) [OPTIONS]"
        exit 1
      end
    end

    def avail_cmds()
      @avail_cmds ||= (self.methods-Object.methods).map(&:to_s).select{|m|m[0..3]=='cmd_'}.map{|m|m[4..-1]}
    end

    def doc_help; 'Output this help.' end
    def cmd_help
      puts "exctl - Execution control; project command-line generator."
      puts "        v#{Exctl.version}\n\n"
      puts "USAGE: exctl (#{avail_cmds.join('|')}) [OPTIONS]\n\n"
      puts avail_cmds.map{|c| hc='doc_'+c; respond_to?(hc) ? '   ' + c.ljust(10) + ':  ' + send(hc) : nil}.compact.join("\n") + "\n\n"
    end

    def cmd_version
      puts Exctl.version
    end

    def doc_init; 'BIN-NAME [DIR=.] - Creates/updates main ctl script and support files in the given DIR.' end
    def cmd_init

      $stderr.puts "just kidding, not implemented yet."
      exit 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exctl-0.0.2 lib/exctl/cli.rb