From c23a5d3d45152d05a519a08b804aecb860fcaec4 Mon Sep 17 00:00:00 2001 From: quinnwai Date: Wed, 7 Jan 2026 08:41:25 -0800 Subject: [PATCH 1/4] update to recent git-drs --- README.md | 4 +-- cmd/meta/main.go | 27 ++++++++++++++----- cmd/publish/main.go | 64 ++++++++++++++++++++++++++++++++++----------- go.mod | 2 +- go.sum | 2 ++ metadata/meta.go | 2 +- publish/publish.go | 3 ++- 7 files changed, 77 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index fdb14ad..9ccf2f6 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ This repo is designed to produce git hook commands that take care of metadata ad ``` git clone repo -forge init -- exactly same as git-dirs init, just a wrapper around it +forge init -- exactly same as git-drs init, just a wrapper around it git add files git commit -m "test" -- same as git-drs -git push origin main -- same as git-dirs +git push origin main -- same as git-drs forge publish [github personal access token] ``` diff --git a/cmd/meta/main.go b/cmd/meta/main.go index 0b2c8d9..ba100bb 100644 --- a/cmd/meta/main.go +++ b/cmd/meta/main.go @@ -1,27 +1,39 @@ package meta import ( + "fmt" + "github.com/calypr/forge/metadata" "github.com/calypr/git-drs/config" "github.com/spf13/cobra" ) -var outPath string +var ( + outPath string + remote string +) + var MetaCmd = &cobra.Command{ Use: "meta", Short: "Autogenerate metadata based off of files that have been uploaded", Long: `Not needed for expected user workflow. Useful for debugging server side operations only.`, - Example: "forge meta [remote]", + Example: "forge meta", Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { - var remoteName string = "origin" - if len(args) > 0 { - remoteName = args[0] + + cfg, err := config.LoadConfig() + if err != nil { + return fmt.Errorf("unable to load config: %w", err) + } + + remoteName, err := cfg.GetRemoteOrDefault(remote) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) } - err := metadata.RunMetaInit(outPath, config.Remote(remoteName)) + err = metadata.CreateMeta(outPath, remoteName) if err != nil { - return err + return fmt.Errorf("could not create metadata: %w", err) } return nil }, @@ -29,4 +41,5 @@ var MetaCmd = &cobra.Command{ func init() { MetaCmd.PersistentFlags().StringVarP(&outPath, "out", "o", metadata.META_DIR, "Directory path to output FHIR .ndjson files") + MetaCmd.Flags().StringVarP(&remote, "remote", "r", "", "target DRS server (default: default_remote)") } diff --git a/cmd/publish/main.go b/cmd/publish/main.go index 0609539..12f0e55 100644 --- a/cmd/publish/main.go +++ b/cmd/publish/main.go @@ -15,14 +15,24 @@ var PublishCmd = &cobra.Command{ Long: `The 'publish' command is how metadata is handled in calypr.`, Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { - var remote config.Remote + var remoteName string + if len(args) == 2 { - remote = config.Remote(args[1]) - fmt.Printf("Using remote: %s\n", remote) + remoteName = args[1] } else { - remote = config.Remote("") - fmt.Printf("Using default remote: %s\n", remote) + remoteName = "" + } + + cfg, err := config.LoadConfig() + if err != nil { + return fmt.Errorf("unable to load config: %w", err) } + remote, err := cfg.GetRemoteOrDefault(remoteName) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) + } + fmt.Printf("Using remote: %s\n", string(remote)) + resp, err := publish.RunPublish(args[0], remote) if err != nil { return err @@ -44,6 +54,10 @@ var ListCmd = &cobra.Command{ } defer closer() vals, err := sc.List() + if err != nil { + return fmt.Errorf("unable to list jobs: %w", err) + } + if len(vals) == 0 { fmt.Printf("There are no jobs to list: %s\n", vals) } else { @@ -62,14 +76,24 @@ var StatusCmd = &cobra.Command{ A specific job's UID can be found from running the list command`, Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) error { - var remote config.Remote + + var remoteName string if len(args) == 2 { - remote = config.Remote(args[1]) - fmt.Printf("Using remote: %s\n", remote) + remoteName = args[1] } else { - remote = config.Remote("") - fmt.Printf("Using default remote: %s\n", remote) + remoteName = "" } + + cfg, err := config.LoadConfig() + if err != nil { + return fmt.Errorf("unable to load config: %w", err) + } + + remote, err := cfg.GetRemoteOrDefault(remoteName) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) + } + sc, closer, err := sower.NewSowerClient(remote) if err != nil { return err @@ -92,14 +116,24 @@ var OutputCmd = &cobra.Command{ A specific job's UID can be found from running the list command`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - var remote config.Remote + var remoteName string if len(args) == 2 { - remote = config.Remote(args[1]) - fmt.Printf("Using remote: %s\n", remote) + remoteName = args[1] } else { - remote = config.Remote("") - fmt.Printf("Using default remote: %s\n", remote) + remoteName = "" + } + + cfg, err := config.LoadConfig() + if err != nil { + return fmt.Errorf("unable to load config: %w", err) + } + + remote, err := cfg.GetRemoteOrDefault(remoteName) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) } + fmt.Printf("Using remote: %s\n", string(remote)) + sc, closer, err := sower.NewSowerClient(remote) if err != nil { return err diff --git a/go.mod b/go.mod index 5aadb6b..b4620dd 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/bytedance/sonic v1.14.2 github.com/calypr/data-client v0.0.0-20251230165452-a95f44240b14 github.com/calypr/gecko v0.0.0-20251110184938-909cb1b668e2 - github.com/calypr/git-drs v0.0.0-20251230165948-81a82438caa4 + github.com/calypr/git-drs v0.0.0-20260105205500-0dbe7e55d1f3 github.com/cockroachdb/errors v1.11.3 github.com/go-git/go-git/v5 v5.12.0 github.com/google/fhir/go v0.7.5-0.20250925033537-1f5b5b9427ff diff --git a/go.sum b/go.sum index fc5f871..61e2833 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,8 @@ github.com/calypr/gecko v0.0.0-20251110184938-909cb1b668e2 h1:ii28j/rzbOaxpUVnON github.com/calypr/gecko v0.0.0-20251110184938-909cb1b668e2/go.mod h1:SJfHDSOaN5xevCor2PVRZxHHJ/WwfAnBBddgnQcUwJo= github.com/calypr/git-drs v0.0.0-20251230165948-81a82438caa4 h1:AWs5hOg6VODWhQ/S9frW+6nz476/fr/9s+nqCJRDKvA= github.com/calypr/git-drs v0.0.0-20251230165948-81a82438caa4/go.mod h1:irPfPmQ5YCcK+GIRvjTqoU+znTL3xs8d/Ex9oX1Xriw= +github.com/calypr/git-drs v0.0.0-20260105205500-0dbe7e55d1f3 h1:xOUDTvAXwUZP/YoCDC2WCEiwjHZbnOsJFhvA5QMytAY= +github.com/calypr/git-drs v0.0.0-20260105205500-0dbe7e55d1f3/go.mod h1:2Z0yl6wUu/IeRPq0ALCakK5EnI1FntRYESEI1YbK4lg= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs= diff --git a/metadata/meta.go b/metadata/meta.go index f5de33a..47268e6 100644 --- a/metadata/meta.go +++ b/metadata/meta.go @@ -56,7 +56,7 @@ type MetaStructure struct { Path string `json:"path"` } -func RunMetaInit(outPath string, remote config.Remote) error { +func CreateMeta(outPath string, remote config.Remote) error { var rsID string var err error cfg, err := config.LoadConfig() diff --git a/publish/publish.go b/publish/publish.go index 432afdc..5b23b07 100644 --- a/publish/publish.go +++ b/publish/publish.go @@ -49,7 +49,8 @@ func RunPublish(token string, profile config.Remote) (*sower.StatusResp, error) if err != nil { return nil, err } - remote, err := repo.Remote(string(profile)) + // NOTE: hardcode to retrieve from git remote "origin" + remote, err := repo.Remote("origin") if err != nil { return nil, fmt.Errorf("failed to get 'origin' remote: %w", err) } From f15bdf1a543b7d886a5270a202e3d4becdf7cdc6 Mon Sep 17 00:00:00 2001 From: quinnwai Date: Wed, 7 Jan 2026 14:36:21 -0800 Subject: [PATCH 2/4] update all cmds to use default_remote --- cmd/config/main.go | 29 +++++++++---- cmd/empty/main.go | 29 ++++++++----- cmd/ping/main.go | 24 +++++++---- cmd/publish/main.go | 101 +++++++++++++++++++++----------------------- 4 files changed, 101 insertions(+), 82 deletions(-) diff --git a/cmd/config/main.go b/cmd/config/main.go index 90367e0..1c90e6c 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -1,27 +1,38 @@ package config import ( + "fmt" + "github.com/calypr/forge/config" - conf "github.com/calypr/git-drs/config" + "github.com/calypr/forge/utils/remoteutil" "github.com/spf13/cobra" ) +var ( + configRemote string +) + var ConfigCmd = &cobra.Command{ - Use: "config [remote]", + Use: "config", Short: "Build skeleton template for CALYPR explorer page config.", Long: `Used for creating a template CALYPR explorer config to build and customize your own config`, - Example: "forge config local", + Example: "forge config --remote local", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - var remote string - if len(args) > 0 { - remote = args[0] - } else { - remote = "" + remote, err := remoteutil.LoadRemoteOrDefault(configRemote) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) } - err := config.RunConfigInit(conf.Remote(remote)) + fmt.Printf("Using remote: %s\n", string(*remote)) + + err = config.RunConfigInit(*remote) if err != nil { return err } return nil }, } + +func init() { + ConfigCmd.Flags().StringVarP(&configRemote, "remote", "r", "", "target DRS server (default: default_remote)") +} diff --git a/cmd/empty/main.go b/cmd/empty/main.go index 6d18bd0..eb34266 100644 --- a/cmd/empty/main.go +++ b/cmd/empty/main.go @@ -4,26 +4,29 @@ import ( "fmt" "github.com/calypr/forge/publish" - "github.com/calypr/git-drs/config" + "github.com/calypr/forge/utils/remoteutil" "github.com/spf13/cobra" ) +var ( + emptyRemote string +) + var EmptyCmd = &cobra.Command{ - Use: "empty [remote]", + Use: "empty ", Short: "empty metadata for a project", Long: `The 'empty' command is how metadata is removed in calypr.`, - Args: cobra.RangeArgs(1, 2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { projectID := args[0] - var remote config.Remote - if len(args) == 2 { - remote = config.Remote(args[1]) - fmt.Printf("Using remote: %s\n", remote) - } else { - remote = config.Remote("") - fmt.Printf("Using default remote: %s\n", remote) + + remote, err := remoteutil.LoadRemoteOrDefault(emptyRemote) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) } - resp, err := publish.RunEmpty(projectID, remote) + fmt.Printf("Using remote: %s\n", string(*remote)) + + resp, err := publish.RunEmpty(projectID, *remote) if err != nil { return err } @@ -31,3 +34,7 @@ var EmptyCmd = &cobra.Command{ return nil }, } + +func init() { + EmptyCmd.Flags().StringVarP(&emptyRemote, "remote", "r", "", "target DRS server (default: default_remote)") +} diff --git a/cmd/ping/main.go b/cmd/ping/main.go index 8a61f39..3768453 100644 --- a/cmd/ping/main.go +++ b/cmd/ping/main.go @@ -5,23 +5,27 @@ import ( "log" "github.com/calypr/forge/client/fence" - "github.com/calypr/git-drs/config" + "github.com/calypr/forge/utils/remoteutil" "github.com/spf13/cobra" "gopkg.in/yaml.v2" ) +var ( + pingRemote string +) + var PingCmd = &cobra.Command{ - Use: "ping [remote]", + Use: "ping", Short: "Ping Calypr instance and return user's project and user permissions", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - var remote config.Remote - if len(args) > 0 { - remote = config.Remote(args[0]) - } else { - remote = config.Remote("origin") + remote, err := remoteutil.LoadRemoteOrDefault(pingRemote) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) } + fmt.Printf("Using remote: %s\n", string(*remote)) - FenceClient, closer, err := fence.NewFenceClient(remote) + FenceClient, closer, err := fence.NewFenceClient(*remote) if err != nil { return err } @@ -41,3 +45,7 @@ var PingCmd = &cobra.Command{ return nil }, } + +func init() { + PingCmd.Flags().StringVarP(&pingRemote, "remote", "r", "", "target DRS server (default: default_remote)") +} diff --git a/cmd/publish/main.go b/cmd/publish/main.go index 12f0e55..68ddfd9 100644 --- a/cmd/publish/main.go +++ b/cmd/publish/main.go @@ -5,35 +5,27 @@ import ( "github.com/calypr/forge/client/sower" "github.com/calypr/forge/publish" - "github.com/calypr/git-drs/config" + "github.com/calypr/forge/utils/remoteutil" "github.com/spf13/cobra" ) +var ( + publishRemote string +) + var PublishCmd = &cobra.Command{ - Use: "publish [remote]", + Use: "publish ", Short: "create metadata upload job for FHIR ndjson files", Long: `The 'publish' command is how metadata is handled in calypr.`, - Args: cobra.RangeArgs(1, 2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - var remoteName string - - if len(args) == 2 { - remoteName = args[1] - } else { - remoteName = "" - } - - cfg, err := config.LoadConfig() - if err != nil { - return fmt.Errorf("unable to load config: %w", err) - } - remote, err := cfg.GetRemoteOrDefault(remoteName) + remote, err := remoteutil.LoadRemoteOrDefault(publishRemote) if err != nil { return fmt.Errorf("could not locate remote: %w", err) } - fmt.Printf("Using remote: %s\n", string(remote)) + fmt.Printf("Using remote: %s\n", string(*remote)) - resp, err := publish.RunPublish(args[0], remote) + resp, err := publish.RunPublish(args[0], *remote) if err != nil { return err } @@ -42,13 +34,23 @@ var PublishCmd = &cobra.Command{ }, } +var ( + listRemote string +) + var ListCmd = &cobra.Command{ - Use: "list [remote]", + Use: "list", Short: "view all of the jobs currently catalogued in sower", Long: `The 'list' command is how jobs are displayed to the user`, - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - sc, closer, err := sower.NewSowerClient(config.Remote(args[0])) + remote, err := remoteutil.LoadRemoteOrDefault(listRemote) + if err != nil { + return fmt.Errorf("could not locate remote: %w", err) + } + fmt.Printf("Using remote: %s\n", string(*remote)) + + sc, closer, err := sower.NewSowerClient(*remote) if err != nil { return err } @@ -69,32 +71,24 @@ var ListCmd = &cobra.Command{ }, } +var ( + statusRemote string +) + var StatusCmd = &cobra.Command{ - Use: "status [remote]", + Use: "status ", Short: "view the status of a specific job on sower", Long: `The 'status' command is how sower job status is communicated to the user. A specific job's UID can be found from running the list command`, - Args: cobra.RangeArgs(1, 2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - - var remoteName string - if len(args) == 2 { - remoteName = args[1] - } else { - remoteName = "" - } - - cfg, err := config.LoadConfig() - if err != nil { - return fmt.Errorf("unable to load config: %w", err) - } - - remote, err := cfg.GetRemoteOrDefault(remoteName) + remote, err := remoteutil.LoadRemoteOrDefault(statusRemote) if err != nil { return fmt.Errorf("could not locate remote: %w", err) } + fmt.Printf("Using remote: %s\n", string(*remote)) - sc, closer, err := sower.NewSowerClient(remote) + sc, closer, err := sower.NewSowerClient(*remote) if err != nil { return err } @@ -109,32 +103,24 @@ var StatusCmd = &cobra.Command{ }, } +var ( + outputRemote string +) + var OutputCmd = &cobra.Command{ - Use: "output [remote]", + Use: "output ", Short: "view output logs of a specific job on sower", Long: `The 'output' command is how sower job output logs are communicated to the user. A specific job's UID can be found from running the list command`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - var remoteName string - if len(args) == 2 { - remoteName = args[1] - } else { - remoteName = "" - } - - cfg, err := config.LoadConfig() - if err != nil { - return fmt.Errorf("unable to load config: %w", err) - } - - remote, err := cfg.GetRemoteOrDefault(remoteName) + remote, err := remoteutil.LoadRemoteOrDefault(outputRemote) if err != nil { return fmt.Errorf("could not locate remote: %w", err) } - fmt.Printf("Using remote: %s\n", string(remote)) + fmt.Printf("Using remote: %s\n", string(*remote)) - sc, closer, err := sower.NewSowerClient(remote) + sc, closer, err := sower.NewSowerClient(*remote) if err != nil { return err } @@ -148,3 +134,10 @@ var OutputCmd = &cobra.Command{ return nil }, } + +func init() { + PublishCmd.Flags().StringVarP(&publishRemote, "remote", "r", "", "target DRS server (default: default_remote)") + ListCmd.Flags().StringVarP(&listRemote, "remote", "r", "", "target DRS server (default: default_remote)") + StatusCmd.Flags().StringVarP(&statusRemote, "remote", "r", "", "target DRS server (default: default_remote)") + OutputCmd.Flags().StringVarP(&outputRemote, "remote", "r", "", "target DRS server (default: default_remote)") +} From 4556ef96d4ef64a869438c4b821b8400faf1da3b Mon Sep 17 00:00:00 2001 From: quinnwai Date: Thu, 8 Jan 2026 07:55:09 -0800 Subject: [PATCH 3/4] hide unneeded completion cmd --- cmd/cmd.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/cmd.go b/cmd/cmd.go index 394fbad..51240db 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -15,6 +15,9 @@ var RootCmd = &cobra.Command{ Short: "A powerful command-line tool for project management.", Long: `Forge is a versatile CLI application designed to streamline various development and project management tasks.`, + CompletionOptions: cobra.CompletionOptions{ + DisableDefaultCmd: true, + }, } func init() { From 14ff99cf11ab24551afb7d6433c27c85d77ac860 Mon Sep 17 00:00:00 2001 From: quinnwai Date: Thu, 8 Jan 2026 08:59:07 -0800 Subject: [PATCH 4/4] add untracked stuff --- utils/remoteutil/remoteutil.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 utils/remoteutil/remoteutil.go diff --git a/utils/remoteutil/remoteutil.go b/utils/remoteutil/remoteutil.go new file mode 100644 index 0000000..fec45c0 --- /dev/null +++ b/utils/remoteutil/remoteutil.go @@ -0,0 +1,22 @@ +package remoteutil + +import ( + "fmt" + + "github.com/calypr/git-drs/config" +) + +// LoadRemoteOrDefault loads the git-drs config and returns the specified remote +// or the default remote if remoteName is empty. +func LoadRemoteOrDefault(remoteName string) (*config.Remote, error) { + cfg, err := config.LoadConfig() + if err != nil { + return nil, fmt.Errorf("unable to load config: %w", err) + } + remote, err := cfg.GetRemoteOrDefault(remoteName) + if err != nil { + return nil, fmt.Errorf("could not locate remote: %w", err) + } + + return &remote, nil +}