Skip to content

Instantly share code, notes, and snippets.

@ess
Created October 13, 2015 22:53
Show Gist options
  • Save ess/1580d3da7f2d4b74f931 to your computer and use it in GitHub Desktop.
Save ess/1580d3da7f2d4b74f931 to your computer and use it in GitHub Desktop.
Trying to make a GLI app work as an in-process Aruba app
#!/usr/bin/env ruby
require 'gli'
module FooCommand
def bootstrap_foo
desc 'Say sup to some foo'
arg 'foo arg'
command :foo do |c|
c.action do |global_options, options, args|
@stdout.puts("Sup, #{args.shift}")
end
end
end
end
module MyApp
class Runner
include GLI::App
include FooCommand
def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
@argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
end
def execute!
program_desc 'Describe your application here'
version '0.0.0'
subcommand_option_handling :normal
arguments :strict
desc 'a global flag'
flag [:g, :global]
pre do |global,command,options,args|
true
end
post do |global,command,options,args|
end
on_error do |exception|
true
end
bootstrap_foo
run(@argv)
end
end
end
exit MyApp::Runner.new(ARGV).execute!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment