Improve command descriptions and argument assertions

This commit is contained in:
Mislav Marohnić 2021-08-16 23:24:11 +02:00
parent 97d8285b58
commit 5e472bc0e5
7 changed files with 32 additions and 41 deletions

View file

@ -14,8 +14,9 @@ import (
func NewCodeCmd() *cobra.Command {
return &cobra.Command{
Use: "code",
Short: "Open a GitHub Codespace in VSCode.",
Use: "code [<codespace>]",
Short: "Open a Codespace in VS Code",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var codespaceName string
if len(args) > 0 {

View file

@ -17,7 +17,8 @@ var repo, branch, machine string
func newCreateCmd() *cobra.Command {
createCmd := &cobra.Command{
Use: "create",
Short: "Create a GitHub Codespace.",
Short: "Create a Codespace",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return Create()
},

View file

@ -2,7 +2,6 @@ package main
import (
"context"
"errors"
"fmt"
"os"
@ -13,8 +12,9 @@ import (
func NewDeleteCmd() *cobra.Command {
deleteCmd := &cobra.Command{
Use: "delete",
Short: "Delete a GitHub Codespace.",
Use: "delete [<codespace>]",
Short: "Delete a Codespace",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var codespaceName string
if len(args) > 0 {
@ -26,22 +26,18 @@ func NewDeleteCmd() *cobra.Command {
deleteAllCmd := &cobra.Command{
Use: "all",
Short: "delete all codespaces",
Long: "delete all codespaces for the user with the current token",
Short: "Delete all Codespaces for the current user",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return DeleteAll()
},
}
deleteByRepoCmd := &cobra.Command{
Use: "repo REPO_NAME",
Short: "delete all codespaces for the repo",
Long: `delete all the codespaces that the user with the current token has in this repo.
This includes all codespaces in all states.`,
Use: "repo <repo>",
Short: "Delete all Codespaces for a repository",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("A Repository name is required.")
}
return DeleteByRepo(args[0])
},
}

View file

@ -14,7 +14,8 @@ import (
func NewListCmd() *cobra.Command {
listCmd := &cobra.Command{
Use: "list",
Short: "List GitHub Codespaces you have on your account.",
Short: "List your Codespaces",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return List()
},

View file

@ -15,8 +15,9 @@ func NewLogsCmd() *cobra.Command {
var tail bool
logsCmd := &cobra.Command{
Use: "logs",
Use: "logs [<codespace>]",
Short: "Access Codespace logs",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var codespaceName string
if len(args) > 0 {

View file

@ -20,7 +20,8 @@ import (
func NewPortsCmd() *cobra.Command {
portsCmd := &cobra.Command{
Use: "ports",
Short: "Forward ports from a GitHub Codespace.",
Short: "List ports in a Codespace",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return Ports()
},
@ -167,14 +168,10 @@ func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Cod
func NewPortsPublicCmd() *cobra.Command {
return &cobra.Command{
Use: "public",
Short: "public",
Long: "public",
Use: "public <codespace> <port>",
Short: "Mark port as public",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("[codespace_name] [source] port number are required.")
}
return updatePortVisibility(args[0], args[1], true)
},
}
@ -182,14 +179,10 @@ func NewPortsPublicCmd() *cobra.Command {
func NewPortsPrivateCmd() *cobra.Command {
return &cobra.Command{
Use: "private",
Short: "private",
Long: "private",
Use: "private <codespace> <port>",
Short: "Mark port as private",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("[codespace_name] [source] port number are required.")
}
return updatePortVisibility(args[0], args[1], false)
},
}
@ -245,13 +238,10 @@ func updatePortVisibility(codespaceName, sourcePort string, public bool) error {
func NewPortsForwardCmd() *cobra.Command {
return &cobra.Command{
Use: "forward",
Short: "forward",
Long: "forward",
Use: "forward <codespace> <source-port> <destination-port>",
Short: "Forward port",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 3 {
return errors.New("[codespace_name] [source] [dst] port number are required.")
}
return forwardPort(args[0], args[1], args[2])
},
}

View file

@ -20,14 +20,15 @@ func NewSSHCmd() *cobra.Command {
sshCmd := &cobra.Command{
Use: "ssh",
Short: "SSH into a GitHub Codespace, for use with running tests/editing in vim, etc.",
Short: "SSH into a Codespace",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return SSH(sshProfile, codespaceName, sshServerPort)
},
}
sshCmd.Flags().StringVarP(&sshProfile, "profile", "", "", "SSH Profile")
sshCmd.Flags().IntVarP(&sshServerPort, "server-port", "", 0, "SSH Server Port")
sshCmd.Flags().StringVarP(&sshProfile, "profile", "", "", "The `name` of the SSH profile to use")
sshCmd.Flags().IntVarP(&sshServerPort, "server-port", "", 0, "SSH server port number")
sshCmd.Flags().StringVarP(&codespaceName, "codespace", "c", "", "Codespace Name")
return sshCmd