Permalink
Browse files

Added a new 'help' command with both one and two argument forms. Remo…

…ved it from TODO list and updated manpage. Should be used in favor of 'usage'.
  • Loading branch information...
soh-cah-toa committed Jul 29, 2011
1 parent 2b7c49d commit 75ec1501b47524a48163709a7411e3499721750c
Showing with 96 additions and 22 deletions.
  1. +0 −1 TODO
  2. BIN man/man1/plumage.1.gz
  3. +78 −19 src/plumage.nqp
  4. +18 −2 t/sanity.t
View
1 TODO
@@ -99,7 +99,6 @@ Plumage:
* Functionality:
* Read meta from repo after fetch/patch/configure
* Help
- * help command
* --help, -h, -? options
* System and local installs
* Where should local installs go by default?
View
Binary file not shown.
View
@@ -20,75 +20,117 @@ load_helper_libraries();
my %COMMANDS := hash(
usage => hash(
action => command_usage,
- args => 'none'
+ args => 'none',
+ usage => 'usage',
+ help => 'This command is here for compatibility purposes. Please use `help` instead.'
+ ),
+ help => hash(
+ action => command_help,
+ args => 'opt_command',
+ usage => 'help [<command>]',
+ help => 'Print a helpful usage message.'
),
version => hash(
action => command_version,
- args => 'none'
+ args => 'none',
+ usage => 'version',
+ help => 'Print program version and copyright.',
),
projects => hash(
action => command_projects,
- args => 'none'
+ args => 'none',
+ usage => 'projects',
+ help => 'List all known projects.'
),
status => hash(
action => command_status,
- args => 'opt_project'
+ args => 'opt_project',
+ usage => 'status [<project>]',
+ help => 'Show status of projects (defaults to all).'
),
info => hash(
action => command_info,
- args => 'project'
+ args => 'project',
+ usage => 'info <project>',
+ help => 'Print summary about a particular project.'
),
metadata => hash(
action => command_info,
- args => 'project'
+ args => 'project',
+ usage => 'metadata <project>',
+ help => 'Print JSON metadata about a particular project.'
),
project_dir => hash(
action => command_project_dir,
- args => 'project'
+ args => 'project',
+ usage => 'project-dir <project>',
+ help => 'Print project\'s top directory'
),
showdeps => hash(
action => command_showdeps,
- args => 'project'
+ args => 'project',
+ usage => 'showdeps <project>',
+ help => 'Show dependency resolution for a project.'
),
fetch => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'fetch <project>',
+ help => 'Download source.'
),
update => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'update <project>',
+ help => 'Update source (falls back to fetch).'
),
configure => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'configure <project>',
+ help => 'Configure source (updates first).'
),
build => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'build <project>',
+ help => 'Build project from source (configures first).'
),
test => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'test <project>',
+ help => 'Test built project (builds first).'
),
smoke => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'smoke <project>',
+ help => 'Smoke test project (builds first).'
),
install => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'install <project>',
+ help => 'Install built files (tests first).'
),
uninstall => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'uninstall <project>',
+ help => 'Uninstalls installed files (not always available).'
),
clean => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'clean <project>',
+ help => 'Clean source tree.'
),
realclean => hash(
action => command_project_action,
- args => 'project'
+ args => 'project',
+ usage => 'realclean <project>',
+ help => 'Clobber/realclean source tree.'
),
);
@@ -267,6 +309,8 @@ sub execute_command ($command) {
if $args eq 'project' && !@*ARGS {
say('Please specify a project to act on.');
}
+ #elsif $args eq 'opt_project' {
+ #}
else {
$action(@*ARGS, :command($command));
}
@@ -287,6 +331,7 @@ sub command_usage () {
print(usage_info());
}
+
sub usage_info () {
return
"Usage: $*PROGRAM_NAME [<options>] <command> [<arguments>]
@@ -324,11 +369,25 @@ Commands:
Get info about Plumage itself:
version Print program version and copyright
- usage Print this usage info
+ help Print a helpful usage message
";
}
+sub command_help ($help_cmd, :$command) {
+ if ?$help_cmd {
+ my $usage := %COMMANDS{$help_cmd[0]}<usage>;
+ my $help := %COMMANDS{$help_cmd[0]}<help>;
+
+ say("$usage\n");
+ say($help);
+ }
+ else {
+ command_usage();
+ }
+}
+
+
sub command_version () {
print(version_info());
}
View
@@ -21,7 +21,7 @@ sub MAIN () {
}
sub run_tests () {
- plan(20);
+ plan(22);
# Fuzz tests
test_invalid();
@@ -37,7 +37,8 @@ sub run_tests () {
test_plumage_fetch_no_args();
# Behavior tests
- test_plumage_usage();
+ #test_plumage_usage();
+ test_plumage_help();
test_plumage_version();
test_plumage_info();
test_plumage_metadata();
@@ -111,12 +112,27 @@ sub test_plumage_fetch_no_args() {
sub test_plumage_usage() {
my $output := qx($PLUMAGE, 'usage');
+
ok($output ~~ /:s Print program version and copyright/,
'usage explains how to view version and copyright');
ok($output ~~ /:s Print summary about a particular project/,
'usage explains how to get info on a project');
}
+sub test_plumage_help() {
+ my $output := qx($PLUMAGE, 'help');
+
+ ok($output ~~ /:s Print program version and copyright/,
+ 'help explains how to view version and copyright');
+ ok($output ~~ /:s Print summary about a particular project/,
+ 'help explains how to get info on a project');
+
+ $output := qx($PLUMAGE, 'help', 'info');
+
+ ok($output ~~ /:s info \<project\>/, 'help info displays usage');
+ ok($output ~~ /:s Print summary about a particular project\./, 'help info displays help');
+}
+
sub test_plumage_version() {
my $output := qx($PLUMAGE, 'version');
ok($! == 0, 'plumage version returns success');

0 comments on commit 75ec150

Please sign in to comment.