This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b976ca0
commit 803165d
Showing
3 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/acorn-io/acorn/pkg/appdefinition" | ||
"github.com/acorn-io/acorn/pkg/build" | ||
"github.com/acorn-io/acorn/pkg/cue" | ||
"github.com/acorn-io/acorn/pkg/flagparams" | ||
cli "github.com/rancher/wrangler-cli" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func NewRender() *cobra.Command { | ||
cmd := cli.Command(&Render{}, cobra.Command{ | ||
Use: "render [flags] DIRECTORY", | ||
SilenceUsage: true, | ||
Short: "Evaluate and display an acorn.cue with deploy params", | ||
Args: cobra.MinimumNArgs(1), | ||
}) | ||
cmd.Flags().SetInterspersed(false) | ||
return cmd | ||
} | ||
|
||
type Render struct { | ||
File string `short:"f" usage:"Name of the dev file" default:"DIRECTORY/acorn.cue"` | ||
} | ||
|
||
func (s *Render) Run(cmd *cobra.Command, args []string) error { | ||
cwd := "." | ||
if len(args) > 0 { | ||
cwd = args[0] | ||
} | ||
|
||
buildFile := build.ResolveFile(s.File, cwd) | ||
data, err := cue.ReadCUE(buildFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
appDef, err := appdefinition.NewAppDefinition(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
appSpec, err := appDef.AppSpec() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
params, err := appDef.DeployParams() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
flags := flagparams.New(s.File, params) | ||
flags.Usage = usage(appSpec) | ||
|
||
deployParams, err := flags.Parse(args) | ||
if pflag.ErrHelp == err { | ||
return nil | ||
} else if err != nil { | ||
return err | ||
} | ||
|
||
appDef, err = appDef.WithDeployParams(deployParams) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
v, err := appDef.JSON() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(v) | ||
|
||
return nil | ||
} |