本文整理匯總了Golang中github.com/github/hub/cmd.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddRemote
func (r *TestRepo) AddRemote(name, url, pushURL string) {
add := cmd.New("git").WithArgs("remote", "add", name, url)
if _, err := add.CombinedOutput(); err != nil {
panic(err)
}
if pushURL != "" {
set := cmd.New("git").WithArgs("remote", "set-url", "--push", name, pushURL)
if _, err := set.CombinedOutput(); err != nil {
panic(err)
}
}
}
示例2: runHelp
func runHelp(helpCmd *Command, args *Args) {
if args.IsParamsEmpty() {
printUsage()
os.Exit(0)
}
command := args.FirstParam()
if command == "hub" {
man := cmd.New("man")
man.WithArg("hub")
err := man.Run()
if err == nil {
os.Exit(0)
} else {
os.Exit(1)
}
}
c := CmdRunner.Lookup(command)
if c != nil && !c.GitExtension {
c.PrintUsage()
os.Exit(0)
} else if c == nil {
if args.HasFlags("-a", "--all") {
args.After("echo", "\nhub custom commands\n")
args.After("echo", " ", strings.Join(customCommands(), " "))
}
}
}
示例3: displayManPage
func displayManPage(manPage string, args *Args) error {
manProgram, _ := utils.CommandPath("man")
if manProgram == "" {
manPage += ".txt"
manProgram = os.Getenv("PAGER")
if manProgram == "" {
manProgram = "less -R"
}
}
programPath, err := utils.CommandPath(args.ProgramPath)
if err != nil {
return err
}
installPrefix := filepath.Join(filepath.Dir(programPath), "..")
manFile, err := localManPage(manPage, installPrefix)
if err != nil {
return err
}
man := cmd.New(manProgram)
man.WithArg(manFile)
if err = man.Run(); err == nil {
os.Exit(0)
} else {
os.Exit(1)
}
return nil
}
示例4: Show
func Show(sha string) (string, error) {
cmd := cmd.New("git")
cmd.WithArg("show").WithArg("-s").WithArg("--format=%s%n%+b").WithArg(sha)
output, err := cmd.CombinedOutput()
output = strings.TrimSpace(output)
return output, err
}
示例5: clone
func (r *TestRepo) clone(repo, dir string) error {
cmd := cmd.New("git").WithArgs("clone", repo, dir)
output, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("error cloning %s to %s: %s", repo, dir, output)
}
return err
}
示例6: openTextEditor
func openTextEditor(program, file string) error {
editCmd := cmd.New(program)
r := regexp.MustCompile("[mg]?vi[m]$")
if r.MatchString(program) {
editCmd.WithArg("-c")
editCmd.WithArg("set ft=gitcommit tw=0 wrap lbr")
}
editCmd.WithArg(file)
return editCmd.Spawn()
}
示例7: gitCmd
func gitCmd(args ...string) *cmd.Cmd {
cmd := cmd.New("git")
for _, v := range GlobalFlags {
cmd.WithArg(v)
}
for _, a := range args {
cmd.WithArg(a)
}
return cmd
}
示例8: Log
func Log(sha1, sha2 string) (string, error) {
execCmd := cmd.New("git")
execCmd.WithArg("-c").WithArg("log.showSignature=false").WithArg("log").WithArg("--no-color")
execCmd.WithArg("--format=%h (%aN, %ar)%n%w(78,3,3)%s%n%+b")
execCmd.WithArg("--cherry")
shaRange := fmt.Sprintf("%s...%s", sha1, sha2)
execCmd.WithArg(shaRange)
outputs, err := execCmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("Can't load git log %s..%s", sha1, sha2)
}
return outputs, nil
}
示例9: Run
func Run(command string, args ...string) error {
cmd := cmd.New("git")
for _, v := range GlobalFlags {
cmd.WithArg(v)
}
cmd.WithArg(command)
for _, a := range args {
cmd.WithArg(a)
}
return cmd.Run()
}
示例10: ToCmd
func (a *Args) ToCmd() *cmd.Cmd {
c := cmd.New(a.Executable)
args := make([]string, 0)
if a.Command != "" {
args = append(args, a.Command)
}
for _, arg := range a.Params {
if arg != "" {
args = append(args, arg)
}
}
return c.WithArgs(args...)
}
示例11: ToCmd
func (a *Args) ToCmd() *cmd.Cmd {
c := cmd.New(a.Executable)
c.WithArgs(a.GlobalFlags...)
if a.Command != "" {
c.WithArg(a.Command)
}
for _, arg := range a.Params {
if arg != "" {
c.WithArg(arg)
}
}
return c
}
示例12: git
func git(input ...string) (outputs []string, err error) {
cmd := cmd.New("git")
for _, i := range input {
cmd.WithArg(i)
}
out, err := cmd.CombinedOutput()
for _, line := range strings.Split(out, "\n") {
line = strings.TrimSpace(line)
if line != "" {
outputs = append(outputs, string(line))
}
}
return
}
示例13: IsGitDir
func IsGitDir(dir string) bool {
cmd := cmd.New("git")
cmd.WithArgs("--git-dir="+dir, "rev-parse", "--git-dir")
return cmd.Success()
}
示例14: ForwardGitHelp
func ForwardGitHelp() error {
cmd := cmd.New("git")
cmd.WithArgs("help")
return cmd.Spawn()
}