From 439c750ef3a40572615897cadbfbc5192638caf7 Mon Sep 17 00:00:00 2001 From: Tanner Welsh Date: Wed, 14 Jan 2015 19:12:17 -0500 Subject: [PATCH 1/3] Display help for base codeunion command Add -h flag to base `codeunion` command; help message will also display when no command or flag is given. --- bin/codeunion | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/bin/codeunion b/bin/codeunion index 83f7096..686c2ae 100755 --- a/bin/codeunion +++ b/bin/codeunion @@ -12,6 +12,25 @@ $LOAD_PATH.unshift File.expand_path("../../lib", bin_file) ENV["PATH"] += ":" + File.expand_path("../../libexec", bin_file) require "codeunion/command/main" +require "optparse" + +parser = OptionParser.new do |opts| + opts.instance_exec do + self.banner = "Usage: codeunion " + + on_tail("-h", "--help", "Print this help message") do + puts self + exit + end + end +end + +parser.order! + +if ARGV.empty? + puts parser + exit +end options = { :command_name => ARGV.first, From 16a06b0f795a6ee46eeecaba6bc09d749c751fae Mon Sep 17 00:00:00 2001 From: Tanner Welsh Date: Wed, 14 Jan 2015 19:56:13 -0500 Subject: [PATCH 2/3] Add list of subcommands to default help message --- bin/codeunion | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/codeunion b/bin/codeunion index 686c2ae..421a025 100755 --- a/bin/codeunion +++ b/bin/codeunion @@ -9,7 +9,16 @@ bin_file = Pathname.new(__FILE__).realpath $LOAD_PATH.unshift File.expand_path("../../lib", bin_file) # Add our gem-specific "libexec" directory to the PATH -ENV["PATH"] += ":" + File.expand_path("../../libexec", bin_file) +subcmd_dir = File.expand_path("../../libexec", bin_file) +ENV["PATH"] += ":" + subcmd_dir + +# Find all available subcommands +subcmd_prefix = "codeunion-" +subcmd_files = Pathname.glob(File.join(subcmd_dir, subcmd_prefix + "*")) + +SUBCOMMANDS = subcmd_files.map do |path| + path.basename.to_s[/#{subcmd_prefix}(.+)/, 1] +end require "codeunion/command/main" require "optparse" @@ -18,6 +27,13 @@ parser = OptionParser.new do |opts| opts.instance_exec do self.banner = "Usage: codeunion " + separator "" + separator "Commands:" + separator SUBCOMMANDS.map { |subcmd| summary_indent + subcmd } + + separator "" + separator "Options:" + on_tail("-h", "--help", "Print this help message") do puts self exit From 6eb30a0ff098ce1773e4087ca0d388779b78909f Mon Sep 17 00:00:00 2001 From: Tanner Welsh Date: Wed, 14 Jan 2015 20:03:09 -0500 Subject: [PATCH 3/3] Show description of tool in default help message --- bin/codeunion | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bin/codeunion b/bin/codeunion index 421a025..3624b12 100755 --- a/bin/codeunion +++ b/bin/codeunion @@ -23,10 +23,19 @@ end require "codeunion/command/main" require "optparse" +description = <