Move cmd/ghcs to pkg/cmd/codespace
- Delete pkg/cmd/codespace/main as it is no longer needed in this codebase
This commit is contained in:
parent
877ad22da6
commit
9e6c11e767
18 changed files with 8 additions and 62 deletions
|
|
@ -1,54 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/cli/cli/v2/cmd/ghcs"
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
"github.com/cli/cli/v2/internal/api"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func main() {
|
||||
token := os.Getenv("GITHUB_TOKEN")
|
||||
rootCmd := ghcs.NewRootCmd(ghcs.NewApp(
|
||||
output.NewLogger(os.Stdout, os.Stderr, false),
|
||||
api.New(token, http.DefaultClient),
|
||||
))
|
||||
|
||||
// Require GITHUB_TOKEN through a Cobra pre-run hook so that Cobra's help system for commands can still
|
||||
// function without the token set.
|
||||
oldPreRun := rootCmd.PersistentPreRunE
|
||||
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
||||
if token == "" {
|
||||
return errTokenMissing
|
||||
}
|
||||
if oldPreRun != nil {
|
||||
return oldPreRun(cmd, args)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if cmd, err := rootCmd.ExecuteC(); err != nil {
|
||||
explainError(os.Stderr, err, cmd)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
var errTokenMissing = errors.New("GITHUB_TOKEN is missing")
|
||||
|
||||
func explainError(w io.Writer, err error, cmd *cobra.Command) {
|
||||
if errors.Is(err, errTokenMissing) {
|
||||
fmt.Fprintln(w, "The GITHUB_TOKEN environment variable is required. Create a Personal Access Token at https://github.com/settings/tokens/new?scopes=repo")
|
||||
fmt.Fprintln(w, "Make sure to enable SSO for your organizations after creating the token.")
|
||||
return
|
||||
}
|
||||
if errors.Is(err, ghcs.ErrTooManyArgs) {
|
||||
_ = cmd.Usage()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -12,8 +12,8 @@ import (
|
|||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/AlecAivazis/survey/v2/terminal"
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
"github.com/cli/cli/v2/internal/api"
|
||||
"github.com/cli/cli/v2/pkg/cmd/codespace/output"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
|
@ -8,9 +8,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
"github.com/cli/cli/v2/internal/api"
|
||||
"github.com/cli/cli/v2/internal/codespaces"
|
||||
"github.com/cli/cli/v2/pkg/cmd/codespace/output"
|
||||
"github.com/fatih/camelcase"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
@ -11,8 +11,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
"github.com/cli/cli/v2/internal/api"
|
||||
"github.com/cli/cli/v2/pkg/cmd/codespace/output"
|
||||
)
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
"github.com/cli/cli/v2/internal/api"
|
||||
"github.com/cli/cli/v2/pkg/cmd/codespace/output"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
@ -11,10 +11,10 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
"github.com/cli/cli/v2/internal/api"
|
||||
"github.com/cli/cli/v2/internal/codespaces"
|
||||
"github.com/cli/cli/v2/internal/liveshare"
|
||||
"github.com/cli/cli/v2/pkg/cmd/codespace/output"
|
||||
"github.com/muhammadmuzzammil1998/jsonc"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
|
@ -5,14 +5,14 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/MakeNowJust/heredoc"
|
||||
"github.com/cli/cli/v2/cmd/ghcs"
|
||||
"github.com/cli/cli/v2/cmd/ghcs/output"
|
||||
ghcsApi "github.com/cli/cli/v2/internal/api"
|
||||
actionsCmd "github.com/cli/cli/v2/pkg/cmd/actions"
|
||||
aliasCmd "github.com/cli/cli/v2/pkg/cmd/alias"
|
||||
apiCmd "github.com/cli/cli/v2/pkg/cmd/api"
|
||||
authCmd "github.com/cli/cli/v2/pkg/cmd/auth"
|
||||
browseCmd "github.com/cli/cli/v2/pkg/cmd/browse"
|
||||
codespaceCmd "github.com/cli/cli/v2/pkg/cmd/codespace"
|
||||
"github.com/cli/cli/v2/pkg/cmd/codespace/output"
|
||||
completionCmd "github.com/cli/cli/v2/pkg/cmd/completion"
|
||||
configCmd "github.com/cli/cli/v2/pkg/cmd/config"
|
||||
extensionCmd "github.com/cli/cli/v2/pkg/cmd/extension"
|
||||
|
|
@ -128,7 +128,7 @@ func bareHTTPClient(f *cmdutil.Factory, version string) func() (*http.Client, er
|
|||
}
|
||||
|
||||
func newCodespaceCmd(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd := ghcs.NewRootCmd(ghcs.NewApp(
|
||||
cmd := codespaceCmd.NewRootCmd(codespaceCmd.NewApp(
|
||||
output.NewLogger(f.IOStreams.Out, f.IOStreams.ErrOut, !f.IOStreams.IsStdoutTTY()),
|
||||
ghcsApi.New("", &lazyLoadedHTTPClient{factory: f}),
|
||||
))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue