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

feat(cmd): use jpath tool to export JSONNET_PATH #427

Merged
merged 3 commits into from
Dec 11, 2020
Merged
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
54 changes: 33 additions & 21 deletions cmd/tk/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
Expand All @@ -30,29 +31,40 @@ func toolCmd() *cli.Command {

func jpathCmd() *cli.Command {
cmd := &cli.Command{
Short: "print information about the jpath",
Use: "jpath",
Run: func(cmd *cli.Command, args []string) error {
pwd, err := os.Getwd()
if err != nil {
return err
}
path, base, root, err := jpath.Resolve(pwd)
if err != nil {
return fmt.Errorf("Resolving JPATH: %s", err)
}
entrypoint, err := jpath.Entrypoint(base)
if err != nil {
return fmt.Errorf("Resolving JPATH: %s", err)
}
fmt.Println("main:", entrypoint)
fmt.Println("rootDir:", root)
fmt.Println("baseDir:", base)
fmt.Println("jpath:", path)
Short: "export JSONNET_PATH for use with other jsonnet tools",
Use: "jpath [<file/dir>]",
Args: workflowArgs,
}

debug := cmd.Flags().BoolP("debug", "d", false, "show debug info")

cmd.Run = func(cmd *cli.Command, args []string) error {
path := args[0]

return nil
},
entrypoint, err := jpath.Entrypoint(path)
if err != nil {
return fmt.Errorf("Resolving JPATH: %s", err)
}

jsonnetpath, base, root, err := jpath.Resolve(entrypoint)
if err != nil {
return fmt.Errorf("Resolving JPATH: %s", err)
}

if *debug {
// log to debug info to stderr
log.Println("main:", entrypoint)
log.Println("rootDir:", root)
log.Println("baseDir:", base)
log.Println("jpath:", jsonnetpath)
}

// print export JSONNET_PATH to stdout
fmt.Printf("%s", strings.Join(jsonnetpath, ":"))

return nil
}

return cmd
}

Expand Down