cmd/ghcs: style tweaks
This commit is contained in:
parent
a48f1070c3
commit
38ff786a7d
10 changed files with 92 additions and 96 deletions
40
api/api.go
40
api/api.go
|
|
@ -1,3 +1,4 @@
|
|||
// TODO(adonovan): rename to package codespaces, and codespaces.Client?
|
||||
package api
|
||||
|
||||
import (
|
||||
|
|
@ -9,7 +10,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -29,10 +29,6 @@ type User struct {
|
|||
Login string `json:"login"`
|
||||
}
|
||||
|
||||
type errResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (a *API) GetUser(ctx context.Context) (*User, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, githubAPI+"/user", nil)
|
||||
if err != nil {
|
||||
|
|
@ -63,7 +59,9 @@ func (a *API) GetUser(ctx context.Context) (*User, error) {
|
|||
}
|
||||
|
||||
func (a *API) errorResponse(b []byte) error {
|
||||
var response errResponse
|
||||
var response struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &response); err != nil {
|
||||
return fmt.Errorf("error unmarshaling error response: %v", err)
|
||||
}
|
||||
|
|
@ -104,14 +102,6 @@ func (a *API) GetRepository(ctx context.Context, nwo string) (*Repository, error
|
|||
return &response, nil
|
||||
}
|
||||
|
||||
type Codespaces []*Codespace
|
||||
|
||||
func (c Codespaces) SortByCreatedAt() {
|
||||
sort.Slice(c, func(i, j int) bool {
|
||||
return c[i].CreatedAt > c[j].CreatedAt
|
||||
})
|
||||
}
|
||||
|
||||
type Codespace struct {
|
||||
Name string `json:"name"`
|
||||
GUID string `json:"guid"`
|
||||
|
|
@ -139,7 +129,7 @@ type CodespaceEnvironmentConnection struct {
|
|||
RelaySAS string `json:"relaySas"`
|
||||
}
|
||||
|
||||
func (a *API) ListCodespaces(ctx context.Context, user *User) (Codespaces, error) {
|
||||
func (a *API) ListCodespaces(ctx context.Context, user *User) ([]*Codespace, error) {
|
||||
req, err := http.NewRequest(
|
||||
http.MethodGet, githubAPI+"/vscs_internal/user/"+user.Login+"/codespaces", nil,
|
||||
)
|
||||
|
|
@ -162,9 +152,9 @@ func (a *API) ListCodespaces(ctx context.Context, user *User) (Codespaces, error
|
|||
return nil, a.errorResponse(b)
|
||||
}
|
||||
|
||||
response := struct {
|
||||
Codespaces Codespaces `json:"codespaces"`
|
||||
}{}
|
||||
var response struct {
|
||||
Codespaces []*Codespace `json:"codespaces"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &response); err != nil {
|
||||
return nil, fmt.Errorf("error unmarshaling response: %v", err)
|
||||
}
|
||||
|
|
@ -297,14 +287,12 @@ func (a *API) GetCodespaceRegionLocation(ctx context.Context) (string, error) {
|
|||
return response.Current, nil
|
||||
}
|
||||
|
||||
type Skus []*Sku
|
||||
|
||||
type Sku struct {
|
||||
type SKU struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
}
|
||||
|
||||
func (a *API) GetCodespacesSkus(ctx context.Context, user *User, repository *Repository, location string) (Skus, error) {
|
||||
func (a *API) GetCodespacesSkus(ctx context.Context, user *User, repository *Repository, location string) ([]*SKU, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, githubAPI+"/vscs_internal/user/"+user.Login+"/skus", nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("err creating request: %v", err)
|
||||
|
|
@ -326,14 +314,14 @@ func (a *API) GetCodespacesSkus(ctx context.Context, user *User, repository *Rep
|
|||
return nil, fmt.Errorf("error reading response body: %v", err)
|
||||
}
|
||||
|
||||
response := struct {
|
||||
Skus Skus `json:"skus"`
|
||||
}{}
|
||||
var response struct {
|
||||
SKUs []*SKU `json:"skus"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &response); err != nil {
|
||||
return nil, fmt.Errorf("error unmarshaling response: %v", err)
|
||||
}
|
||||
|
||||
return response.Skus, nil
|
||||
return response.SKUs, nil
|
||||
}
|
||||
|
||||
type createCodespaceRequest struct {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewCodeCmd() *cobra.Command {
|
||||
func newCodeCmd() *cobra.Command {
|
||||
useInsiders := false
|
||||
|
||||
codeCmd := &cobra.Command{
|
||||
|
|
@ -24,7 +24,7 @@ func NewCodeCmd() *cobra.Command {
|
|||
if len(args) > 0 {
|
||||
codespaceName = args[0]
|
||||
}
|
||||
return Code(codespaceName, useInsiders)
|
||||
return code(codespaceName, useInsiders)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ func NewCodeCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(NewCodeCmd())
|
||||
rootCmd.AddCommand(newCodeCmd())
|
||||
}
|
||||
|
||||
func Code(codespaceName string, useInsiders bool) error {
|
||||
func code(codespaceName string, useInsiders bool) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func newCreateCmd() *cobra.Command {
|
|||
Short: "Create a Codespace",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return Create()
|
||||
return create()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ func init() {
|
|||
rootCmd.AddCommand(newCreateCmd())
|
||||
}
|
||||
|
||||
func Create() error {
|
||||
func create() error {
|
||||
ctx := context.Background()
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
locationCh := getLocation(ctx, apiClient)
|
||||
|
|
@ -176,7 +176,7 @@ func getMachineName(ctx context.Context, user *api.User, repo *api.Repository, l
|
|||
}
|
||||
|
||||
skuNames := make([]string, 0, len(skus))
|
||||
skuByName := make(map[string]*api.Sku)
|
||||
skuByName := make(map[string]*api.SKU)
|
||||
for _, sku := range skus {
|
||||
nameParts := camelcase.Split(sku.Name)
|
||||
machineName := strings.Title(strings.ToLower(nameParts[0]))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewDeleteCmd() *cobra.Command {
|
||||
func newDeleteCmd() *cobra.Command {
|
||||
deleteCmd := &cobra.Command{
|
||||
Use: "delete [<codespace>]",
|
||||
Short: "Delete a Codespace",
|
||||
|
|
@ -22,7 +22,7 @@ func NewDeleteCmd() *cobra.Command {
|
|||
if len(args) > 0 {
|
||||
codespaceName = args[0]
|
||||
}
|
||||
return Delete(codespaceName)
|
||||
return delete_(codespaceName)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ func NewDeleteCmd() *cobra.Command {
|
|||
Short: "Delete all Codespaces for the current user",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return DeleteAll()
|
||||
return deleteAll()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ func NewDeleteCmd() *cobra.Command {
|
|||
Short: "Delete all Codespaces for a repository",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return DeleteByRepo(args[0])
|
||||
return deleteByRepo(args[0])
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -50,10 +50,10 @@ func NewDeleteCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(NewDeleteCmd())
|
||||
rootCmd.AddCommand(newDeleteCmd())
|
||||
}
|
||||
|
||||
func Delete(codespaceName string) error {
|
||||
func delete_(codespaceName string) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, false)
|
||||
|
|
@ -74,10 +74,10 @@ func Delete(codespaceName string) error {
|
|||
|
||||
log.Println("Codespace deleted.")
|
||||
|
||||
return List(&ListOptions{})
|
||||
return list(&listOptions{})
|
||||
}
|
||||
|
||||
func DeleteAll() error {
|
||||
func deleteAll() error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, false)
|
||||
|
|
@ -105,10 +105,10 @@ func DeleteAll() error {
|
|||
log.Printf("Codespace deleted: %s\n", c.Name)
|
||||
}
|
||||
|
||||
return List(&ListOptions{})
|
||||
return list(&listOptions{})
|
||||
}
|
||||
|
||||
func DeleteByRepo(repo string) error {
|
||||
func deleteByRepo(repo string) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, false)
|
||||
|
|
@ -146,5 +146,5 @@ func DeleteByRepo(repo string) error {
|
|||
return fmt.Errorf("No codespace was found for repository: %s", repo)
|
||||
}
|
||||
|
||||
return List(&ListOptions{})
|
||||
return list(&listOptions{})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,32 +10,32 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type ListOptions struct {
|
||||
AsJSON bool
|
||||
type listOptions struct {
|
||||
asJSON bool
|
||||
}
|
||||
|
||||
func NewListCmd() *cobra.Command {
|
||||
opts := &ListOptions{}
|
||||
func newListCmd() *cobra.Command {
|
||||
opts := &listOptions{}
|
||||
|
||||
listCmd := &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List your Codespaces",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return List(opts)
|
||||
return list(opts)
|
||||
},
|
||||
}
|
||||
|
||||
listCmd.Flags().BoolVar(&opts.AsJSON, "json", false, "Output as JSON")
|
||||
listCmd.Flags().BoolVar(&opts.asJSON, "json", false, "Output as JSON")
|
||||
|
||||
return listCmd
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(NewListCmd())
|
||||
rootCmd.AddCommand(newListCmd())
|
||||
}
|
||||
|
||||
func List(opts *ListOptions) error {
|
||||
func list(opts *listOptions) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ func List(opts *ListOptions) error {
|
|||
return fmt.Errorf("error getting codespaces: %v", err)
|
||||
}
|
||||
|
||||
table := output.NewTable(os.Stdout, opts.AsJSON)
|
||||
table := output.NewTable(os.Stdout, opts.asJSON)
|
||||
table.SetHeader([]string{"Name", "Repository", "Branch", "State", "Created At"})
|
||||
for _, codespace := range codespaces {
|
||||
table.Append([]string{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewLogsCmd() *cobra.Command {
|
||||
func newLogsCmd() *cobra.Command {
|
||||
var tail bool
|
||||
|
||||
logsCmd := &cobra.Command{
|
||||
|
|
@ -24,7 +24,7 @@ func NewLogsCmd() *cobra.Command {
|
|||
if len(args) > 0 {
|
||||
codespaceName = args[0]
|
||||
}
|
||||
return Logs(tail, codespaceName)
|
||||
return logs(tail, codespaceName)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -34,10 +34,10 @@ func NewLogsCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(NewLogsCmd())
|
||||
rootCmd.AddCommand(newLogsCmd())
|
||||
}
|
||||
|
||||
func Logs(tail bool, codespaceName string) error {
|
||||
func logs(tail bool, codespaceName string) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, false)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package main
|
||||
|
||||
// TODO(adonovan): write 'help' commands, in manner of the 'go' tool.
|
||||
// Document GITHUB_TOKEN.
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -16,7 +19,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
var Version = "DEV"
|
||||
var version = "DEV"
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "ghcs",
|
||||
|
|
@ -24,7 +27,7 @@ var rootCmd = &cobra.Command{
|
|||
|
||||
Running commands requires the GITHUB_TOKEN environment variable to be set to a
|
||||
token to access the GitHub API with.`,
|
||||
Version: Version,
|
||||
Version: version,
|
||||
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if os.Getenv("GITHUB_TOKEN") == "" {
|
||||
|
|
@ -42,5 +45,5 @@ func explainError(w io.Writer, err error) {
|
|||
fmt.Fprintln(w, "Make sure to enable SSO for your organizations after creating the token.")
|
||||
return
|
||||
}
|
||||
// fmt.Fprintf(w, "%v\n", err)
|
||||
fmt.Fprintf(w, "%v\n", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,48 +19,48 @@ import (
|
|||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type PortsOptions struct {
|
||||
CodespaceName string
|
||||
AsJSON bool
|
||||
type portsOptions struct {
|
||||
codespaceName string
|
||||
asJSON bool
|
||||
}
|
||||
|
||||
func NewPortsCmd() *cobra.Command {
|
||||
opts := &PortsOptions{}
|
||||
func newPortsCmd() *cobra.Command {
|
||||
opts := &portsOptions{}
|
||||
|
||||
portsCmd := &cobra.Command{
|
||||
Use: "ports",
|
||||
Short: "List ports in a Codespace",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return Ports(opts)
|
||||
return ports(opts)
|
||||
},
|
||||
}
|
||||
|
||||
portsCmd.Flags().StringVarP(&opts.CodespaceName, "codespace", "c", "", "The `name` of the Codespace to use")
|
||||
portsCmd.Flags().BoolVar(&opts.AsJSON, "json", false, "Output as JSON")
|
||||
portsCmd.Flags().StringVarP(&opts.codespaceName, "codespace", "c", "", "The `name` of the Codespace to use")
|
||||
portsCmd.Flags().BoolVar(&opts.asJSON, "json", false, "Output as JSON")
|
||||
|
||||
portsCmd.AddCommand(NewPortsPublicCmd())
|
||||
portsCmd.AddCommand(NewPortsPrivateCmd())
|
||||
portsCmd.AddCommand(NewPortsForwardCmd())
|
||||
portsCmd.AddCommand(newPortsPublicCmd())
|
||||
portsCmd.AddCommand(newPortsPrivateCmd())
|
||||
portsCmd.AddCommand(newPortsForwardCmd())
|
||||
|
||||
return portsCmd
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(NewPortsCmd())
|
||||
rootCmd.AddCommand(newPortsCmd())
|
||||
}
|
||||
|
||||
func Ports(opts *PortsOptions) error {
|
||||
func ports(opts *portsOptions) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, opts.AsJSON)
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, opts.asJSON)
|
||||
|
||||
user, err := apiClient.GetUser(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting user: %v", err)
|
||||
}
|
||||
|
||||
codespace, token, err := codespaces.GetOrChooseCodespace(ctx, apiClient, user, opts.CodespaceName)
|
||||
codespace, token, err := codespaces.GetOrChooseCodespace(ctx, apiClient, user, opts.codespaceName)
|
||||
if err != nil {
|
||||
if err == codespaces.ErrNoCodespaces {
|
||||
return err
|
||||
|
|
@ -82,17 +82,18 @@ func Ports(opts *PortsOptions) error {
|
|||
}
|
||||
|
||||
devContainerResult := <-devContainerCh
|
||||
if devContainerResult.Err != nil {
|
||||
_, _ = log.Errorf("Failed to get port names: %v\n", devContainerResult.Err.Error())
|
||||
if devContainerResult.err != nil {
|
||||
_, _ = log.Errorf("Failed to get port names: %v\n", devContainerResult.err.Error())
|
||||
// TODO(adonovan): should this cause non-zero exit?
|
||||
}
|
||||
|
||||
table := output.NewTable(os.Stdout, opts.AsJSON)
|
||||
table := output.NewTable(os.Stdout, opts.asJSON)
|
||||
table.SetHeader([]string{"Label", "Source Port", "Destination Port", "Public", "Browse URL"})
|
||||
for _, port := range ports {
|
||||
sourcePort := strconv.Itoa(port.SourcePort)
|
||||
var portName string
|
||||
if devContainerResult.DevContainer != nil {
|
||||
if attributes, ok := devContainerResult.DevContainer.PortAttributes[sourcePort]; ok {
|
||||
if devContainerResult.devContainer != nil {
|
||||
if attributes, ok := devContainerResult.devContainer.PortAttributes[sourcePort]; ok {
|
||||
portName = attributes.Label
|
||||
}
|
||||
}
|
||||
|
|
@ -125,8 +126,8 @@ func getPorts(ctx context.Context, lsclient *liveshare.Client) (liveshare.Ports,
|
|||
}
|
||||
|
||||
type devContainerResult struct {
|
||||
DevContainer *devContainer
|
||||
Err error
|
||||
devContainer *devContainer
|
||||
err error
|
||||
}
|
||||
|
||||
type devContainer struct {
|
||||
|
|
@ -168,7 +169,7 @@ func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Cod
|
|||
return ch
|
||||
}
|
||||
|
||||
func NewPortsPublicCmd() *cobra.Command {
|
||||
func newPortsPublicCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "public <codespace> <port>",
|
||||
Short: "Mark port as public",
|
||||
|
|
@ -180,7 +181,7 @@ func NewPortsPublicCmd() *cobra.Command {
|
|||
}
|
||||
}
|
||||
|
||||
func NewPortsPrivateCmd() *cobra.Command {
|
||||
func newPortsPrivateCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "private <codespace> <port>",
|
||||
Short: "Mark port as private",
|
||||
|
|
@ -239,7 +240,7 @@ func updatePortVisibility(log *output.Logger, codespaceName, sourcePort string,
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewPortsForwardCmd() *cobra.Command {
|
||||
func newPortsForwardCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "forward <codespace> <source-port>:<destination-port>",
|
||||
Short: "Forward ports",
|
||||
|
|
@ -289,14 +290,14 @@ func forwardPorts(log *output.Logger, codespaceName string, ports []string) erro
|
|||
for _, portPair := range portPairs {
|
||||
pp := portPair
|
||||
|
||||
srcstr := strconv.Itoa(portPair.Src)
|
||||
if err := server.StartSharing(gctx, "share-"+srcstr, pp.Src); err != nil {
|
||||
srcstr := strconv.Itoa(portPair.src)
|
||||
if err := server.StartSharing(gctx, "share-"+srcstr, pp.src); err != nil {
|
||||
return fmt.Errorf("start sharing port: %v", err)
|
||||
}
|
||||
|
||||
g.Go(func() error {
|
||||
log.Println("Forwarding port: " + srcstr + " ==> " + strconv.Itoa(pp.Dst))
|
||||
portForwarder := liveshare.NewPortForwarder(lsclient, server, pp.Dst)
|
||||
log.Println("Forwarding port: " + srcstr + " ==> " + strconv.Itoa(pp.dst))
|
||||
portForwarder := liveshare.NewPortForwarder(lsclient, server, pp.dst)
|
||||
if err := portForwarder.Start(gctx); err != nil {
|
||||
return fmt.Errorf("error forwarding port: %v", err)
|
||||
}
|
||||
|
|
@ -313,16 +314,17 @@ func forwardPorts(log *output.Logger, codespaceName string, ports []string) erro
|
|||
}
|
||||
|
||||
type portPair struct {
|
||||
Src, Dst int
|
||||
src, dst int
|
||||
}
|
||||
|
||||
// getPortPairs parses a list of strings of form "%d:%d" into pairs of numbers.
|
||||
func getPortPairs(ports []string) ([]portPair, error) {
|
||||
pp := make([]portPair, 0, len(ports))
|
||||
|
||||
for _, portString := range ports {
|
||||
parts := strings.Split(portString, ":")
|
||||
if len(parts) < 2 {
|
||||
return pp, fmt.Errorf("port pair: '%v' is not valid", portString)
|
||||
return nil, fmt.Errorf("port pair: '%v' is not valid", portString)
|
||||
}
|
||||
|
||||
srcp, err := strconv.Atoi(parts[0])
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewSSHCmd() *cobra.Command {
|
||||
func newSSHCmd() *cobra.Command {
|
||||
var sshProfile, codespaceName string
|
||||
var sshServerPort int
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ func NewSSHCmd() *cobra.Command {
|
|||
Short: "SSH into a Codespace",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return SSH(sshProfile, codespaceName, sshServerPort)
|
||||
return ssh(sshProfile, codespaceName, sshServerPort)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -36,10 +36,10 @@ func NewSSHCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(NewSSHCmd())
|
||||
rootCmd.AddCommand(newSSHCmd())
|
||||
}
|
||||
|
||||
func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
||||
func ssh(sshProfile, codespaceName string, sshServerPort int) error {
|
||||
apiClient := api.New(os.Getenv("GITHUB_TOKEN"))
|
||||
ctx := context.Background()
|
||||
log := output.NewLogger(os.Stdout, os.Stderr, false)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
|
|
@ -25,7 +26,9 @@ func ChooseCodespace(ctx context.Context, apiClient *api.API, user *api.User) (*
|
|||
return nil, ErrNoCodespaces
|
||||
}
|
||||
|
||||
codespaces.SortByCreatedAt()
|
||||
sort.Slice(codespaces, func(i, j int) bool {
|
||||
return codespaces[i].CreatedAt > codespaces[j].CreatedAt
|
||||
})
|
||||
|
||||
codespacesByName := make(map[string]*api.Codespace)
|
||||
codespacesNames := make([]string, 0, len(codespaces))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue