Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Creating a new command

Alex Chesters edited this page Oct 18, 2015 · 3 revisions

Follow the instructions below to create a new command

  1. Create a new file in the commands directory named my-command.rb
  2. Do your work in my-command.rb. This file should be in a similar format to below (it must contain an execute function and an options function):
    module GHI
      module Commands
        class MyCommand < Command
    
          def options
              OptionParser.new do |opts|
                  opts.banner = 'usage: ghi mycommand'
                  opts.on '-a', '--all', 'some flag information' do
                      object[:key] = 'value'
                  end
              end
          end
    
          def execute
              begin
                  options.parse! args
                  @repo ||= ARGV[0] if ARGV.one?
              rescue OptionParser::InvalidOption => e
                  fallback.parse! e.args
                  retry
              end
              puts "Hello, world!"
          end
    
        end
      end
    end  
  3. Add your new file to the build manifest in the Rakefile
  4. Add your new command to commands.rb
  5. Add your new command to ghi help