Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up commands #248

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cmd/timoni/bundle_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var bundleApplyCmd = &cobra.Command{
# Pass secret values from stdin
cat ./bundle_secrets.cue | timoni bundle apply -f ./bundle.cue -f -
`,
Args: cobra.NoArgs,
RunE: runBundleApplyCmd,
}

Expand Down Expand Up @@ -102,18 +103,23 @@ func init() {
func runBundleApplyCmd(cmd *cobra.Command, _ []string) error {
start := time.Now()
files := bundleApplyArgs.files
if len(files) == 0 {
return fmt.Errorf("no bundle provided with -f")
}
var stdinFile string
for i, file := range files {
if file == "-" {
path, err := saveReaderToFile(cmd.InOrStdin())
stdinFile, err := saveReaderToFile(cmd.InOrStdin())
if err != nil {
return err
}

defer os.Remove(path)

files[i] = path
files[i] = stdinFile
break
}
}
if stdinFile != "" {
defer os.Remove(stdinFile)
}

tmpDir, err := os.MkdirTemp("", apiv1.FieldManager)
if err != nil {
Expand Down
16 changes: 11 additions & 5 deletions cmd/timoni/bundle_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var bundleBuildCmd = &cobra.Command{
# Pass secret values from stdin
cat ./bundle_secrets.cue | timoni bundle build -f ./bundle.cue -f -
`,
Args: cobra.NoArgs,
RunE: runBundleBuildCmd,
}

Expand Down Expand Up @@ -77,18 +78,23 @@ func init() {

func runBundleBuildCmd(cmd *cobra.Command, _ []string) error {
files := bundleBuildArgs.files
if len(files) == 0 {
return fmt.Errorf("no bundle provided with -f")
}
var stdinFile string
for i, file := range files {
if file == "-" {
path, err := saveReaderToFile(cmd.InOrStdin())
stdinFile, err := saveReaderToFile(cmd.InOrStdin())
if err != nil {
return err
}

defer os.Remove(path)

files[i] = path
files[i] = stdinFile
break
}
}
if stdinFile != "" {
defer os.Remove(stdinFile)
}

tmpDir, err := os.MkdirTemp("", apiv1.FieldManager)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions cmd/timoni/bundle_vet.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ with Timoni's schema and optionally prints the computed value.
-r runtime.cue \
--print-value
`,
Args: cobra.NoArgs,
RunE: runBundleVetCmd,
}

Expand Down Expand Up @@ -84,6 +85,23 @@ func init() {
func runBundleVetCmd(cmd *cobra.Command, args []string) error {
log := LoggerFrom(cmd.Context())
files := bundleVetArgs.files
if len(files) == 0 {
return fmt.Errorf("no bundle provided with -f")
}
var stdinFile string
for i, file := range files {
if file == "-" {
stdinFile, err := saveReaderToFile(cmd.InOrStdin())
if err != nil {
return err
}
files[i] = stdinFile
break
}
}
if stdinFile != "" {
defer os.Remove(stdinFile)
}

tmpDir, err := os.MkdirTemp("", apiv1.FieldManager)
if err != nil {
Expand Down
19 changes: 13 additions & 6 deletions cmd/timoni/mod_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ import (
var initModCmd = &cobra.Command{
Use: "init [MODULE NAME] [PATH]",
Short: "Create a module along with common files and directories",
Example: ` # create a module in the current directory
timoni mod init my-app .
Example: ` # Create a module in the current directory
timoni mod init my-app

# Create a module at the specified path
timoni mod init my-app ./modules
`,
RunE: runInitModCmd,
}
Expand All @@ -56,12 +59,16 @@ const (
)

func runInitModCmd(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return fmt.Errorf("module name and path are required")
if len(args) < 1 {
return fmt.Errorf("module name is required")
}

initModArgs.name = args[0]
initModArgs.path = args[1]

if len(args) == 2 {
initModArgs.path = args[1]
} else {
initModArgs.path = "."
}

log := LoggerFrom(cmd.Context())

Expand Down
20 changes: 19 additions & 1 deletion cmd/timoni/runtime_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import (

var runtimeBuildCmd = &cobra.Command{
Use: "build",
Short: "Build queries the cluster, extracts the values and prints them",
Short: "Build validates the runtime definition, queries the cluster, extracts the values and prints them",
Example: ` # Print the runtime values from a cluster
timoni runtime build -f runtime.cue
`,
Args: cobra.NoArgs,
RunE: runRuntimeBuildCmd,
}

Expand All @@ -53,6 +54,23 @@ func init() {

func runRuntimeBuildCmd(cmd *cobra.Command, args []string) error {
files := runtimeBuildArgs.files
if len(files) == 0 {
return fmt.Errorf("no runtime provided with -f")
}
var stdinFile string
for i, file := range files {
if file == "-" {
stdinFile, err := saveReaderToFile(cmd.InOrStdin())
if err != nil {
return err
}
files[i] = stdinFile
break
}
}
if stdinFile != "" {
defer os.Remove(stdinFile)
}

rt, err := buildRuntime(files)
if err != nil {
Expand Down