@@ -38,7 +38,8 @@ func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command
3838 The expansion may specify additional arguments and flags. If the expansion
3939 includes positional placeholders such as '$1', '$2', etc., any extra arguments
4040 that follow the invocation of an alias will be inserted appropriately.
41- Reads from STDIN if not specified.
41+ Reads from STDIN if '-' is specified as the expansion parameter. This can be useful
42+ for commands with mixed quotes or multiple lines.
4243
4344 If '--shell' is specified, the alias will be run through a shell interpreter (sh). This allows you
4445 to compose commands with "|" or redirect with ">". Note that extra arguments following the alias
@@ -48,7 +49,8 @@ func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command
4849 Platform note: on Windows, shell aliases are executed via "sh" as installed by Git For Windows. If
4950 you have installed git on Windows in some other way, shell aliases may not work for you.
5051
51- Quotes must always be used when defining a command as in the examples.
52+ Quotes must always be used when defining a command as in the examples unless you pass '-'
53+ as the expansion parameter and pipe your command to 'gh alias set'.
5254 ` ),
5355 Example : heredoc .Doc (`
5456 $ gh alias set pv 'pr view'
@@ -70,19 +72,16 @@ func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command
7072 #=> gh issue list --label="epic" | grep "foo"
7173
7274 # users.txt contains multiline 'api graphql -F name="$1" ...' with mixed quotes
73- $ gh alias set users < users.txt
75+ $ gh alias set users - < users.txt
7476 $ gh users octocat
7577 #=> gh api graphql -F name="octocat" ...
7678 ` ),
77- Args : cobra .RangeArgs ( 1 , 2 ),
79+ Args : cobra .ExactArgs ( 2 ),
7880 RunE : func (cmd * cobra.Command , args []string ) error {
7981 opts .RootCmd = cmd .Root ()
8082
8183 opts .Name = args [0 ]
82-
83- if len (args ) > 1 {
84- opts .Expansion = args [1 ]
85- }
84+ opts .Expansion = args [1 ]
8685
8786 if runF != nil {
8887 return runF (opts )
@@ -165,7 +164,7 @@ func validCommand(rootCmd *cobra.Command, expansion string) bool {
165164}
166165
167166func getExpansion (opts * SetOptions ) (string , error ) {
168- if opts .Expansion == "" {
167+ if opts .Expansion == "- " {
169168 stdin , err := ioutil .ReadAll (opts .IO .In )
170169 if err != nil {
171170 return "" , fmt .Errorf ("failed to read from STDIN: %w" , err )
0 commit comments