@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/MakeNowJust/heredoc"
1313 "github.com/cli/go-gh/v2/pkg/api"
14+ "github.com/github/gh-runtime-cli/internal/config"
1415 "github.com/spf13/cobra"
1516)
1617
@@ -19,6 +20,7 @@ type deployCmdFlags struct {
1920 app string
2021 revisionName string
2122 sha string
23+ config string
2224}
2325
2426func zipDirectory (sourceDir , destinationZip string ) error {
@@ -91,25 +93,35 @@ func init() {
9193 Use : "deploy" ,
9294 Short : "Deploy app to GitHub Runtime" ,
9395 Long : heredoc .Doc (`
94- Deploys a directory to a GitHub Runtime app
96+ Deploys a directory to a GitHub Runtime app.
97+ You can specify the app name using --app flag, --config flag to read from a runtime config file,
98+ or it will automatically read from runtime.config.json in the current directory if it exists.
9599 ` ),
96100 Example : heredoc .Doc (`
97101 $ gh runtime deploy --dir ./dist --app my-app [--sha <sha>]
98102 # => Deploys the contents of the 'dist' directory to the app named 'my-app'.
103+
104+ $ gh runtime deploy --dir ./dist --config runtime.config.json
105+ # => Deploys using app name from the config file.
106+
107+ $ gh runtime deploy --dir ./dist
108+ # => Deploys using app name from runtime.config.json in current directory (if it exists).
99109 ` ),
100110 RunE : func (cmd * cobra.Command , args []string ) error {
101111 if deployCmdFlags .dir == "" {
102112 return fmt .Errorf ("--dir flag is required" )
103113 }
104- if deployCmdFlags .app == "" {
105- return fmt .Errorf ("--app flag is required" )
114+
115+ appName , err := config .ResolveAppName (deployCmdFlags .app , deployCmdFlags .config )
116+ if err != nil {
117+ return err
106118 }
107119
108120 if _ , err := os .Stat (deployCmdFlags .dir ); os .IsNotExist (err ) {
109121 return fmt .Errorf ("directory '%s' does not exist" , deployCmdFlags .dir )
110122 }
111123
112- _ , err : = os .ReadDir (deployCmdFlags .dir )
124+ _ , err = os .ReadDir (deployCmdFlags .dir )
113125 if err != nil {
114126 return fmt .Errorf ("error reading directory '%s': %v" , deployCmdFlags .dir , err )
115127 }
@@ -127,7 +139,7 @@ func init() {
127139 return fmt .Errorf ("error creating REST client: %v" , err )
128140 }
129141
130- deploymentsUrl := fmt .Sprintf ("runtime/%s/deployment/bundle" , deployCmdFlags . app )
142+ deploymentsUrl := fmt .Sprintf ("runtime/%s/deployment/bundle" , appName )
131143 params := url.Values {}
132144
133145 if deployCmdFlags .revisionName != "" {
@@ -161,6 +173,7 @@ func init() {
161173 }
162174 deployCmd .Flags ().StringVarP (& deployCmdFlags .dir , "dir" , "d" , "" , "The directory to deploy" )
163175 deployCmd .Flags ().StringVarP (& deployCmdFlags .app , "app" , "a" , "" , "The app to deploy" )
176+ deployCmd .Flags ().StringVarP (& deployCmdFlags .config , "config" , "c" , "" , "Path to runtime config file" )
164177 deployCmd .Flags ().StringVarP (& deployCmdFlags .revisionName , "revision-name" , "r" , "" , "The revision name to deploy" )
165178 deployCmd .Flags ().StringVarP (& deployCmdFlags .sha , "sha" , "s" , "" , "SHA of the app being deployed" )
166179
0 commit comments