Skip to content

Commit 291cded

Browse files
authored
Merge pull request cli#1500 from cli/issue-commands-isolate
Isolate remaining old-style commands
2 parents ec2e8a8 + aa774c4 commit 291cded

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4105
-3568
lines changed

cmd/gen-docs/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"os"
66
"strings"
77

8-
"github.com/cli/cli/command"
8+
"github.com/cli/cli/pkg/cmd/root"
9+
"github.com/cli/cli/pkg/cmdutil"
10+
"github.com/cli/cli/pkg/iostreams"
911
"github.com/spf13/cobra/doc"
1012
"github.com/spf13/pflag"
1113
)
@@ -35,13 +37,16 @@ func main() {
3537
fatal("no dir set")
3638
}
3739

40+
io, _, _, _ := iostreams.Test()
41+
rootCmd := root.NewCmdRoot(&cmdutil.Factory{IOStreams: io}, "", "")
42+
3843
err := os.MkdirAll(*dir, 0755)
3944
if err != nil {
4045
fatal(err)
4146
}
4247

4348
if *website {
44-
err = doc.GenMarkdownTreeCustom(command.RootCmd, *dir, filePrepender, linkHandler)
49+
err = doc.GenMarkdownTreeCustom(rootCmd, *dir, filePrepender, linkHandler)
4550
if err != nil {
4651
fatal(err)
4752
}
@@ -54,7 +59,7 @@ func main() {
5459
Source: "", //source and manual are just put at the top of the manpage, before name
5560
Manual: "", //if source is an empty string, it's set to "Auto generated by spf13/cobra"
5661
}
57-
err = doc.GenManTree(command.RootCmd, header, *dir)
62+
err = doc.GenManTree(rootCmd, header, *dir)
5863
if err != nil {
5964
fatal(err)
6065
}

cmd/gh/main.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212

1313
"github.com/cli/cli/command"
1414
"github.com/cli/cli/internal/config"
15+
"github.com/cli/cli/internal/run"
16+
"github.com/cli/cli/pkg/cmd/alias/expand"
17+
"github.com/cli/cli/pkg/cmd/factory"
18+
"github.com/cli/cli/pkg/cmd/root"
1519
"github.com/cli/cli/pkg/cmdutil"
1620
"github.com/cli/cli/update"
1721
"github.com/cli/cli/utils"
@@ -31,25 +35,44 @@ func main() {
3135

3236
hasDebug := os.Getenv("DEBUG") != ""
3337

34-
stderr := utils.NewColorable(os.Stderr)
38+
cmdFactory := factory.New(command.Version)
39+
stderr := cmdFactory.IOStreams.ErrOut
40+
rootCmd := root.NewCmdRoot(cmdFactory, command.Version, command.BuildDate)
3541

3642
expandedArgs := []string{}
3743
if len(os.Args) > 0 {
3844
expandedArgs = os.Args[1:]
3945
}
4046

41-
cmd, _, err := command.RootCmd.Traverse(expandedArgs)
42-
if err != nil || cmd == command.RootCmd {
47+
cmd, _, err := rootCmd.Traverse(expandedArgs)
48+
if err != nil || cmd == rootCmd {
4349
originalArgs := expandedArgs
4450
isShell := false
45-
expandedArgs, isShell, err = command.ExpandAlias(os.Args)
51+
52+
cfg, err := cmdFactory.Config()
53+
if err != nil {
54+
fmt.Fprintf(stderr, "failed to read configuration: %s\n", err)
55+
os.Exit(2)
56+
}
57+
58+
expandedArgs, isShell, err = expand.ExpandAlias(cfg, os.Args, nil)
4659
if err != nil {
4760
fmt.Fprintf(stderr, "failed to process aliases: %s\n", err)
4861
os.Exit(2)
4962
}
5063

64+
if hasDebug {
65+
fmt.Fprintf(stderr, "%v -> %v\n", originalArgs, expandedArgs)
66+
}
67+
5168
if isShell {
52-
err = command.ExecuteShellAlias(expandedArgs)
69+
externalCmd := exec.Command(expandedArgs[0], expandedArgs[1:]...)
70+
externalCmd.Stderr = os.Stderr
71+
externalCmd.Stdout = os.Stdout
72+
externalCmd.Stdin = os.Stdin
73+
preparedCmd := run.PrepareCmd(externalCmd)
74+
75+
err = preparedCmd.Run()
5376
if err != nil {
5477
if ee, ok := err.(*exec.ExitError); ok {
5578
os.Exit(ee.ExitCode())
@@ -61,19 +84,15 @@ func main() {
6184

6285
os.Exit(0)
6386
}
64-
65-
if hasDebug {
66-
fmt.Fprintf(stderr, "%v -> %v\n", originalArgs, expandedArgs)
67-
}
6887
}
6988

70-
command.RootCmd.SetArgs(expandedArgs)
89+
rootCmd.SetArgs(expandedArgs)
7190

72-
if cmd, err := command.RootCmd.ExecuteC(); err != nil {
73-
printError(os.Stderr, err, cmd, hasDebug)
91+
if cmd, err := rootCmd.ExecuteC(); err != nil {
92+
printError(stderr, err, cmd, hasDebug)
7493
os.Exit(1)
7594
}
76-
if command.HasFailed() {
95+
if root.HasFailed() {
7796
os.Exit(1)
7897
}
7998

@@ -85,7 +104,6 @@ func main() {
85104
ansi.Color(newRelease.Version, "cyan"),
86105
ansi.Color(newRelease.URL, "yellow"))
87106

88-
stderr := utils.NewColorable(os.Stderr)
89107
fmt.Fprintf(stderr, "\n\n%s\n\n", msg)
90108
}
91109
}

command/alias.go

Lines changed: 0 additions & 234 deletions
This file was deleted.

0 commit comments

Comments
 (0)