@@ -40,8 +40,9 @@ func LoadManifestAndSetNPA(opts *ManifestOptions) (*rofl.Manifest, *rofl.Deploym
4040 cfg := cliConfig .Global ()
4141 npa := common .GetNPASelection (cfg )
4242
43- manifest , d , err := MaybeLoadManifestAndSetNPA (cfg , npa , DeploymentName , opts )
43+ manifest , resolvedName , d , err := MaybeLoadManifestAndSetNPA (cfg , npa , DeploymentName , opts )
4444 cobra .CheckErr (err )
45+ DeploymentName = resolvedName
4546 if opts != nil && opts .NeedAppID && ! d .HasAppID () {
4647 cobra .CheckErr (fmt .Errorf ("deployment '%s' does not have an app ID set, maybe you need to run `oasis rofl create`" , DeploymentName ))
4748 }
@@ -51,34 +52,44 @@ func LoadManifestAndSetNPA(opts *ManifestOptions) (*rofl.Manifest, *rofl.Deploym
5152// MaybeLoadManifestAndSetNPA loads the ROFL app manifest and reconfigures the
5253// network/paratime/account selection.
5354//
54- // In case there is an error in loading the manifest, it is returned.
55- func MaybeLoadManifestAndSetNPA (cfg * cliConfig.Config , npa * common.NPASelection , deployment string , opts * ManifestOptions ) (* rofl.Manifest , * rofl.Deployment , error ) {
55+ // In case there is an error in loading the manifest, it is returned. The resolved deployment name
56+ // is always returned alongside the deployment.
57+ func MaybeLoadManifestAndSetNPA (cfg * cliConfig.Config , npa * common.NPASelection , deployment string , opts * ManifestOptions ) (* rofl.Manifest , string , * rofl.Deployment , error ) {
5658 manifest , err := rofl .LoadManifest ()
5759 if err != nil {
58- return nil , nil , err
60+ return nil , "" , nil , err
5961 }
6062
6163 // Warn if manifest was created with an older CLI version.
6264 checkToolingVersion (manifest )
6365
66+ // Resolve deployment name when not explicitly provided.
67+ if deployment == "" {
68+ deployment = manifest .DefaultDeployment ()
69+ }
70+ if deployment == "" {
71+ if len (manifest .Deployments ) == 0 {
72+ return nil , "" , nil , fmt .Errorf ("no deployments configured\n Hint: use `oasis rofl create` to register a new ROFL app and create a deployment" )
73+ }
74+ printAvailableDeployments (manifest )
75+ return nil , "" , nil , fmt .Errorf ("no default deployment configured\n Hint: use `oasis rofl set-default <name>` to set a default deployment" )
76+ }
77+
6478 d , ok := manifest .Deployments [deployment ]
6579 if ! ok {
66- fmt .Println ("The following deployments are configured in the app manifest:" )
67- for name := range manifest .Deployments {
68- fmt .Printf (" - %s\n " , name )
69- }
70- return nil , nil , fmt .Errorf ("deployment '%s' does not exist" , deployment )
80+ printAvailableDeployments (manifest )
81+ return nil , "" , nil , fmt .Errorf ("deployment '%s' does not exist" , deployment )
7182 }
7283
7384 switch d .Network {
7485 case "" :
7586 if npa .Network == nil {
76- return nil , nil , fmt .Errorf ("no network selected" )
87+ return nil , "" , nil , fmt .Errorf ("no network selected" )
7788 }
7889 default :
7990 npa .Network = cfg .Networks .All [d .Network ]
8091 if npa .Network == nil {
81- return nil , nil , fmt .Errorf ("network '%s' does not exist" , d .Network )
92+ return nil , "" , nil , fmt .Errorf ("network '%s' does not exist" , d .Network )
8293 }
8394 npa .NetworkName = d .Network
8495 }
@@ -88,7 +99,7 @@ func MaybeLoadManifestAndSetNPA(cfg *cliConfig.Config, npa *common.NPASelection,
8899 default :
89100 npa .ParaTime = npa .Network .ParaTimes .All [d .ParaTime ]
90101 if npa .ParaTime == nil {
91- return nil , nil , fmt .Errorf ("paratime '%s' does not exist" , d .ParaTime )
102+ return nil , "" , nil , fmt .Errorf ("paratime '%s' does not exist" , d .ParaTime )
92103 }
93104 npa .ParaTimeName = d .ParaTime
94105 }
@@ -104,12 +115,22 @@ func MaybeLoadManifestAndSetNPA(cfg *cliConfig.Config, npa *common.NPASelection,
104115 npa .Account = accCfg
105116 npa .AccountName = d .Admin
106117 case opts != nil && opts .NeedAdmin :
107- return nil , nil , err
118+ return nil , "" , nil , err
108119 default :
109120 // Admin account is not valid, but it is also not required, so do not override.
110121 }
111122 }
112- return manifest , d , nil
123+ return manifest , deployment , d , nil
124+ }
125+
126+ func printAvailableDeployments (manifest * rofl.Manifest ) {
127+ if len (manifest .Deployments ) == 0 {
128+ return
129+ }
130+ fmt .Println ("The following deployments are configured in the app manifest:" )
131+ for name := range manifest .Deployments {
132+ fmt .Printf (" - %s\n " , name )
133+ }
113134}
114135
115136// GetOrcFilename generates a filename based on the project name and deployment.
0 commit comments