@@ -30,9 +30,9 @@ public function run($argv, $home)
30
30
31
31
list ($ argv , $ options ) = $ this ->parseOutOurOptions ($ argv , $ optionDefaultValues );
32
32
33
- if ( reset ( $ argv ) == ' help ' ) {
34
- $ this -> help ( $ argv );
35
- return 0 ;
33
+ $ helpArg = $ this -> getHelpArgValue ( $ argv );
34
+ if (! empty ( $ helpArg )) {
35
+ return $ this -> help ( $ helpArg ) ;
36
36
}
37
37
38
38
$ commandList = $ this ->separateProjectAndGetCommandList ($ argv , $ home , $ options );
@@ -42,44 +42,47 @@ public function run($argv, $home)
42
42
return $ this ->runCommandList ($ commandList , $ options );
43
43
}
44
44
45
- public function help ($ argv )
45
+ /**
46
+ * Returns the first argument after `help`, or the
47
+ * first argument if `--help` is present. Otherwise,
48
+ * returns an empty string.
49
+ */
50
+ public function getHelpArgValue ($ argv )
46
51
{
47
- // Future: support 'help <command>'?
48
- print <<<EOT
49
- The 'cgr' tool is a "safer" alternative to 'composer global require'.
50
- Installing projects with cgr helps avoid dependency conflicts between
51
- different tools. Use 'cgr' wherever 'composer global require' is recommended.
52
-
53
- Examples:
54
-
55
- Install a project:
56
- ------------------
57
- $ cgr drush/drush
52
+ $ hasHelp = false ;
53
+ $ helpArg = '' ;
58
54
59
- Display the info of a project:
60
- -----------------------------
61
- $ cgr info drush/drush
62
-
63
- Display the info of all projects installed via 'cgr':
64
- ----------------------------------------------------
65
- $ cgr info
55
+ foreach ( $ argv as $ arg ) {
56
+ if (( $ arg == ' help ' ) || ( $ arg == ' --help ' ) || ( $ arg == ' -h ' )) {
57
+ $ hasHelp = true ;
58
+ } elseif (( $ arg [ 0 ] != ' - ' ) && empty ( $ helpArg )) {
59
+ $ helpArg = $ arg ;
60
+ }
61
+ }
66
62
67
- Update a project:
68
- -----------------
69
- $ cgr update drush/drush
63
+ if (! $ hasHelp ) {
64
+ return false ;
65
+ }
70
66
71
- Update all projects installed via 'cgr':
72
- ----------------------------------------
73
- $ cgr update
67
+ if ( empty ( $ helpArg )) {
68
+ return ' help ' ;
69
+ }
74
70
75
- Remove a project:
76
- -----------------
77
- $ cgr remove drush/drush
71
+ return $ helpArg ;
72
+ }
78
73
79
- For more information, see: https://github.com/consolidation/cgr
74
+ public function help ($ helpArg )
75
+ {
76
+ $ helpFile = dirname (__DIR__ ) . '/help/ ' . $ helpArg ;
80
77
78
+ if (!file_exists ($ helpFile )) {
79
+ print "No help available for ' $ helpArg' \n" ;
80
+ return 1 ;
81
+ }
81
82
82
- EOT ;
83
+ $ helpContents = file_get_contents ($ helpFile );
84
+ print $ helpContents ;
85
+ return 0 ;
83
86
}
84
87
85
88
/**
0 commit comments