I’ve created my own gem using the GLI 2.0 gem for all the nice command line structure. It’s working fine, but I’d also like to support data piped in.
my_prog new some_file # this is ok already
some_process | my_prog # how do I add this?
Somewhere I need to check how it was called (somehow) and then act appropriately. I’ve simplified a little, but my current code is below.
require 'rubygems'
require 'gli'
include GLI::App
desc 'My example'
command :new do |c|
desc 'Specify input file'
arg_name 'filename'
c.flag [:i,:input]
c.action do |global_options,options,args|
exit_now!("Input file must be specified") if options[:o].nil?
exit_now!("New failed") unless File.exists?(options[:o])
end
end
exit run(ARGV)
Just to sum up the discussion above:
GLI currently mutates
ARGV, soARGFshould work fine inside theactionblock of a command, even if you’re piping in. BUT, GLI does require some sort of command to run, even if it’s overriding the default ofhelpto the command in question.