"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/extensions/command.go" between
gh-cli-1.12.1.tar.gz and gh-cli-1.13.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

command.go  (gh-cli-1.12.1):command.go  (gh-cli-1.13.1)
skipping to change at line 13 skipping to change at line 13
import ( import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"strings" "strings"
"github.com/MakeNowJust/heredoc" "github.com/MakeNowJust/heredoc"
"github.com/cli/cli/git" "github.com/cli/cli/git"
"github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/extensions"
"github.com/cli/cli/utils" "github.com/cli/cli/utils"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
func NewCmdExtensions(f *cmdutil.Factory) *cobra.Command { func NewCmdExtensions(f *cmdutil.Factory) *cobra.Command {
m := f.ExtensionManager m := f.ExtensionManager
io := f.IOStreams io := f.IOStreams
extCmd := cobra.Command{ extCmd := cobra.Command{
Use: "extensions", Use: "extensions",
skipping to change at line 76 skipping to change at line 77
Short: "Install a gh extension from a repository", Short: "Install a gh extension from a repository",
Args: cmdutil.MinimumArgs(1, "must specify a repository to install from"), Args: cmdutil.MinimumArgs(1, "must specify a repository to install from"),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if args[0] == "." { if args[0] == "." {
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
return err return err
} }
return m.InstallLocal(wd) return m.InstallLocal(wd)
} }
repo, err := ghrepo.FromFullName(args[0]) repo, err := ghrepo.FromFullName(args[0])
if err != nil { if err != nil {
return err return err
} }
if !strings.HasPrefix(repo.RepoName(), "gh-") { if err := checkValidExtension(cmd.Root(), m, repo
return errors.New("the repository name mu .RepoName()); err != nil {
st start with `gh-`") return err
} }
cfg, err := f.Config() cfg, err := f.Config()
if err != nil { if err != nil {
return err return err
} }
protocol, _ := cfg.Get(repo.RepoHost(), "git_prot ocol") protocol, _ := cfg.Get(repo.RepoHost(), "git_prot ocol")
return m.Install(ghrepo.FormatRemoteURL(repo, pro tocol), io.Out, io.ErrOut) return m.Install(ghrepo.FormatRemoteURL(repo, pro tocol), io.Out, io.ErrOut)
}, },
}, },
func() *cobra.Command { func() *cobra.Command {
var flagAll bool var flagAll bool
skipping to change at line 124 skipping to change at line 127
}, },
} }
cmd.Flags().BoolVar(&flagAll, "all", false, "Upgrade all extensions") cmd.Flags().BoolVar(&flagAll, "all", false, "Upgrade all extensions")
return cmd return cmd
}(), }(),
&cobra.Command{ &cobra.Command{
Use: "remove", Use: "remove",
Short: "Remove an installed extension", Short: "Remove an installed extension",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return m.Remove(args[0]) extName := args[0]
if err := m.Remove(extName); err != nil {
return err
}
if io.IsStdoutTTY() {
cs := io.ColorScheme()
fmt.Fprintf(io.Out, "%s Removed extension
%s\n", cs.SuccessIcon(), extName)
}
return nil
}, },
}, },
) )
extCmd.Hidden = true extCmd.Hidden = true
return &extCmd return &extCmd
} }
func checkValidExtension(rootCmd *cobra.Command, m extensions.ExtensionManager,
extName string) error {
if !strings.HasPrefix(extName, "gh-") {
return errors.New("extension repository name must start with `gh-
`")
}
commandName := strings.TrimPrefix(extName, "gh-")
if c, _, err := rootCmd.Traverse([]string{commandName}); err != nil {
return err
} else if c != rootCmd {
return fmt.Errorf("%q matches the name of a built-in command", co
mmandName)
}
for _, ext := range m.List() {
if ext.Name() == commandName {
return fmt.Errorf("there is already an installed extensio
n that provides the %q command", commandName)
}
}
return nil
}
 End of changes. 6 change blocks. 
4 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)