@@ -70,10 +70,12 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
7070 return t .Render ()
7171 },
7272 },
73- & cobra.Command {
74- Use : "install <repository>" ,
75- Short : "Install a gh extension from a repository" ,
76- Long : heredoc .Doc (`
73+ func () * cobra.Command {
74+ var pinFlag string
75+ cmd := & cobra.Command {
76+ Use : "install <repository>" ,
77+ Short : "Install a gh extension from a repository" ,
78+ Long : heredoc .Doc (`
7779 Install a GitHub repository locally as a GitHub CLI extension.
7880
7981 The repository argument can be specified in "owner/repo" format as well as a full URL.
@@ -84,41 +86,44 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
8486
8587 See the list of available extensions at <https://github.com/topics/gh-extension>
8688 ` ),
87- Example : heredoc .Doc (`
89+ Example : heredoc .Doc (`
8890 $ gh extension install owner/gh-extension
8991 $ gh extension install https://git.example.com/owner/gh-extension
9092 $ gh extension install .
9193 ` ),
92- Args : cmdutil .MinimumArgs (1 , "must specify a repository to install from" ),
93- RunE : func (cmd * cobra.Command , args []string ) error {
94- if args [0 ] == "." {
95- wd , err := os .Getwd ()
94+ Args : cmdutil .MinimumArgs (1 , "must specify a repository to install from" ),
95+ RunE : func (cmd * cobra.Command , args []string ) error {
96+ if args [0 ] == "." {
97+ wd , err := os .Getwd ()
98+ if err != nil {
99+ return err
100+ }
101+ return m .InstallLocal (wd )
102+ }
103+
104+ repo , err := ghrepo .FromFullName (args [0 ])
96105 if err != nil {
97106 return err
98107 }
99- return m .InstallLocal (wd )
100- }
101-
102- repo , err := ghrepo .FromFullName (args [0 ])
103- if err != nil {
104- return err
105- }
106108
107- if err := checkValidExtension (cmd .Root (), m , repo .RepoName ()); err != nil {
108- return err
109- }
109+ if err := checkValidExtension (cmd .Root (), m , repo .RepoName ()); err != nil {
110+ return err
111+ }
110112
111- if err := m .Install (repo ); err != nil {
112- return err
113- }
113+ if err := m .Install (repo , pinFlag ); err != nil {
114+ return err
115+ }
114116
115- if io .IsStdoutTTY () {
116- cs := io .ColorScheme ()
117- fmt .Fprintf (io .Out , "%s Installed extension %s\n " , cs .SuccessIcon (), args [0 ])
118- }
119- return nil
120- },
121- },
117+ if io .IsStdoutTTY () {
118+ cs := io .ColorScheme ()
119+ fmt .Fprintf (io .Out , "%s Installed extension %s\n " , cs .SuccessIcon (), args [0 ])
120+ }
121+ return nil
122+ },
123+ }
124+ cmd .Flags ().StringVar (& pinFlag , "pin" , "" , "pin extension to a release tag or commit sha" )
125+ return cmd
126+ }(),
122127 func () * cobra.Command {
123128 var flagAll bool
124129 var flagForce bool
0 commit comments