4040 deployOffer string
4141 deployMachine string
4242 deployForce bool
43- deployShowOffers bool
4443 deployReplaceMachine bool
4544
4645 deployCmd = & cobra.Command {
@@ -129,7 +128,7 @@ var (
129128
130129 fmt .Printf ("Using provider: %s (%s)\n " , machine .Provider , providerAddr )
131130
132- if deployShowOffers {
131+ if roflCommon . ShowOffers {
133132 // Display all offers supported by the provider.
134133 showProviderOffers (ctx , npa , conn , * providerAddr )
135134 return
@@ -203,7 +202,7 @@ var (
203202 }
204203 cobra .CheckErr (totalPrice .Mul (qTermCount ))
205204 tp := types .NewBaseUnits (totalPrice , offer .Payment .Native .Denomination )
206- fmt .Printf ("Selected per-%s pricing term, total price is " , term2str (term ))
205+ fmt .Printf ("Selected per-%s pricing term, total price is " , roflCommon . FormatTerm (term ))
207206 tp .PrettyPrint (ctx , "" , os .Stdout )
208207 fmt .Println ("." )
209208 // Warn the user about the non-refundable rental policy before first renting.
@@ -350,7 +349,7 @@ func pushBundleToOciRepository(orcFilename string, ociRepository string) (string
350349func detectTerm (offer * roflmarket.Offer ) (term roflmarket.Term ) {
351350 if offer == nil {
352351 cobra .CheckErr (fmt .Errorf ("no offers exist to determine payment term" ))
353- return // Linter complains otherwise.
352+ return term // Linter complains otherwise.
354353 }
355354 if offer .Payment .Native == nil {
356355 cobra .CheckErr (fmt .Errorf ("no payment terms available for offer '%s'" , offer .ID ))
@@ -362,7 +361,7 @@ func detectTerm(offer *roflmarket.Offer) (term roflmarket.Term) {
362361 if _ , ok := offer .Payment .Native .Terms [term ]; ! ok {
363362 cobra .CheckErr (fmt .Errorf ("term '%s' is not available for offer '%s'" , roflCommon .Term , offer .ID ))
364363 }
365- return
364+ return term
366365 }
367366
368367 // Take the longest payment period.
@@ -372,20 +371,20 @@ func detectTerm(offer *roflmarket.Offer) (term roflmarket.Term) {
372371 term = t
373372 }
374373 }
375- return
374+ return term
376375}
377376
378377func fetchProviderOffers (ctx context.Context , npa * common.NPASelection , conn connection.Connection , provider types.Address ) (offers []* roflmarket.Offer , err error ) {
379378 offers , err = conn .Runtime (npa .ParaTime ).ROFLMarket .Offers (ctx , client .RoundLatest , provider )
380379 if err != nil {
381380 err = fmt .Errorf ("failed to query provider: %s" , err )
382- return
381+ return offers , err
383382 }
384383 // Order offers, newer first.
385384 sort .Slice (offers , func (i , j int ) bool {
386385 return bytes .Compare (offers [i ].ID [:], offers [j ].ID [:]) > 0
387386 })
388- return
387+ return offers , err
389388}
390389
391390func showProviderOffers (ctx context.Context , npa * common.NPASelection , conn connection.Connection , provider types.Address ) {
@@ -409,19 +408,9 @@ func showProviderOffer(ctx context.Context, offer *roflmarket.Offer) {
409408 name = "<unnamed>"
410409 }
411410
412- var tee string
413- switch offer .Resources .TEE {
414- case roflmarket .TeeTypeSGX :
415- tee = "sgx"
416- case roflmarket .TeeTypeTDX :
417- tee = "tdx"
418- default :
419- tee = "<unknown>"
420- }
421-
422411 fmt .Printf ("- %s [%s]\n " , name , offer .ID )
423412 fmt .Printf (" TEE: %s | Memory: %d MiB | vCPUs: %d | Storage: %.2f GiB\n " ,
424- tee ,
413+ roflCommon . FormatTeeType ( offer . Resources . TEE ) ,
425414 offer .Resources .Memory ,
426415 offer .Resources .CPUCount ,
427416 float64 (offer .Resources .Storage )/ 1024. ,
@@ -455,27 +444,13 @@ func showProviderOffer(ctx context.Context, offer *roflmarket.Offer) {
455444
456445 bu := types .NewBaseUnits (price , offer .Payment .Native .Denomination )
457446 bu .PrettyPrint (ctx , "" , os .Stdout )
458- fmt .Printf ("/%s" , term2str (term ))
447+ fmt .Printf ("/%s" , roflCommon . FormatTerm (term ))
459448 gotPrev = true
460449 }
461450 fmt .Println ()
462451 }
463452}
464453
465- // Helper to convert roflmarket term into string.
466- func term2str (term roflmarket.Term ) string {
467- switch term {
468- case roflmarket .TermHour :
469- return "hour"
470- case roflmarket .TermMonth :
471- return "month"
472- case roflmarket .TermYear :
473- return "year"
474- default :
475- return "<unknown>"
476- }
477- }
478-
479454func resolveAndMarshalPermissions (npa * common.NPASelection , permissions map [string ][]string ) (string , error ) {
480455 perms := make (scheduler.Permissions )
481456 for action , addresses := range permissions {
@@ -514,12 +489,12 @@ func init() {
514489 providerFlags .StringVar (& deployOffer , "offer" , "" , "set the provider's offer identifier" )
515490 providerFlags .StringVar (& deployMachine , "machine" , buildRofl .DefaultMachineName , "machine to deploy into" )
516491 providerFlags .BoolVar (& deployForce , "force" , false , "force deployment" )
517- providerFlags .BoolVar (& deployShowOffers , "show-offers" , false , "show all provider offers and quit" )
518492 providerFlags .BoolVar (& deployReplaceMachine , "replace-machine" , false , "rent a new machine if the provided one expired" )
519493
520494 deployCmd .Flags ().AddFlagSet (common .AccountFlag )
521495 deployCmd .Flags ().AddFlagSet (common .RuntimeTxFlags )
522496 deployCmd .Flags ().AddFlagSet (providerFlags )
497+ deployCmd .Flags ().AddFlagSet (roflCommon .ShowOffersFlag )
523498 deployCmd .Flags ().AddFlagSet (roflCommon .DeploymentFlags )
524499 deployCmd .Flags ().AddFlagSet (roflCommon .WipeFlags )
525500 deployCmd .Flags ().AddFlagSet (roflCommon .TermFlags )
0 commit comments