-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'run' command which accepts the whole ptool cmdline as single arg
- Loading branch information
Showing
5 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package versioncmd | ||
package alias | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package run | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/google/shlex" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/sagan/ptool/cmd" | ||
) | ||
|
||
var command = &cobra.Command{ | ||
Use: "run {cmdline}", | ||
Short: `Run cmdline. Accept the whole cmdline as single arg, e.g.: 'ptool run "status local -t"'.`, | ||
Long: `Run cmdline. Accept the whole cmdline as single arg, e.g.: 'ptool run "status local -t"'.`, | ||
DisableFlagParsing: true, | ||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
RunE: run, | ||
} | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(command) | ||
} | ||
|
||
func run(_ *cobra.Command, args []string) error { | ||
cmdline := args[0] | ||
cmdlineArgs, err := shlex.Split(cmdline) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse cmdline '%s': %v", cmdline, err) | ||
} | ||
os.Args = append([]string{os.Args[0]}, cmdlineArgs...) | ||
fmt.Printf("Run cmdline: %v\n", os.Args[1:]) | ||
return cmd.RootCmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters