diff --git a/README.md b/README.md index 52c5d79..2be2eed 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,13 @@ make build 3. Run: ```bash -uigraph sync +uigraph sync --enterprise ``` +`--enterprise` points the CLI at the UiGraph gateway (`--enterprise=DEV` for the dev +environment), so there is no need to set +`UIGRAPH_GATEWAY_URL`. Self-hosted instances keep using `--api-url` or `UIGRAPH_GATEWAY_URL`. + Example: ```yaml @@ -80,6 +84,8 @@ apis: uigraph sync uigraph sync --config ./config/.uigraph.yaml uigraph sync --dry-run +uigraph sync --enterprise +uigraph sync --enterprise=DEV --dry-run ``` Record a release from a tag-triggered pipeline job. The version, notes and diff --git a/cmd/release.go b/cmd/release.go index 2e136e8..545c62a 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -30,6 +30,7 @@ var releaseCmd = &cobra.Command{ Long: `Records a single release event at the moment a tag is created, for pipelines that cut releases as a CI/CD step. Run this from a tag-triggered job; it resolves the version, release notes and commit range from git and posts one timeline event. Requires the UIGRAPH_TOKEN environment variable.`, + Args: cobra.NoArgs, RunE: runRelease, } @@ -42,6 +43,9 @@ func init() { releaseCmd.Flags().StringVar(&releaseTitle, "title", "", "Event title (defaults to the version)") releaseCmd.Flags().StringVar(&configPath, "config", ".uigraph.yaml", "Path to config file") releaseCmd.Flags().StringVar(&apiURL, "api-url", "", "Gateway API URL (defaults to UIGRAPH_GATEWAY_URL env var)") + releaseCmd.Flags().StringVar(&enterpriseEnv, "enterprise", "", "Record the release on the UiGraph gateway ("+enterpriseGatewayURL+"); pass --enterprise=DEV for "+enterpriseDevGatewayURL) + releaseCmd.Flags().Lookup("enterprise").NoOptDefVal = "DEFAULT" + releaseCmd.MarkFlagsMutuallyExclusive("api-url", "enterprise") releaseCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print the event without sending it to the gateway") } @@ -54,11 +58,21 @@ func runRelease(cmd *cobra.Command, args []string) error { os.Exit(1) } + if enterpriseEnv == "DEFAULT" { + apiURL = enterpriseGatewayURL + } + if enterpriseEnv == "DEV" { + apiURL = enterpriseDevGatewayURL + } + if enterpriseEnv != "" && apiURL == "" { + fmt.Fprintf(os.Stderr, "Error: --enterprise accepts no value or =DEV, got %q\n", enterpriseEnv) + os.Exit(1) + } if apiURL == "" { apiURL = os.Getenv("UIGRAPH_GATEWAY_URL") } if apiURL == "" { - fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --api-url or UIGRAPH_GATEWAY_URL environment variable)") + fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --enterprise, --api-url or UIGRAPH_GATEWAY_URL environment variable)") os.Exit(1) } diff --git a/cmd/root.go b/cmd/root.go index 4834ff3..72d7744 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,11 @@ import ( "github.com/spf13/cobra" ) +const ( + enterpriseGatewayURL = "https://console.uigraph.app/gateway" + enterpriseDevGatewayURL = "https://console.dev.uigraph.app/gateway" +) + var rootCmd = &cobra.Command{ Use: "uigraph", Short: "UiGraph CLI - Sync services and APIs to UiGraph Gateway", diff --git a/cmd/sync.go b/cmd/sync.go index e751e82..548095f 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -24,10 +24,11 @@ import ( ) var ( - configPath string - apiURL string - dryRun bool - verbose bool + configPath string + apiURL string + enterpriseEnv string + dryRun bool + verbose bool ) var syncCmd = &cobra.Command{ @@ -35,12 +36,16 @@ var syncCmd = &cobra.Command{ Short: "Sync service and APIs to UiGraph Gateway", Long: `Reads .uigraph.yaml, captures git metadata, and syncs service, API groups, architecture diagrams, test packs/test cases, and database schemas (when configured) to the gateway. This command is designed to run in CI/CD environments and requires UIGRAPH_TOKEN environment variable.`, + Args: cobra.NoArgs, RunE: runSync, } func init() { syncCmd.Flags().StringVar(&configPath, "config", ".uigraph.yaml", "Path to config file") syncCmd.Flags().StringVar(&apiURL, "api-url", "", "Gateway API URL (defaults to UIGRAPH_GATEWAY_URL env var)") + syncCmd.Flags().StringVar(&enterpriseEnv, "enterprise", "", "Sync to the UiGraph gateway ("+enterpriseGatewayURL+"); pass --enterprise=DEV for "+enterpriseDevGatewayURL) + syncCmd.Flags().Lookup("enterprise").NoOptDefVal = "DEFAULT" + syncCmd.MarkFlagsMutuallyExclusive("api-url", "enterprise") syncCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Print payloads without sending to gateway") syncCmd.Flags().BoolVar(&verbose, "verbose", false, "Log every MLflow and gateway request with its duration") } @@ -107,11 +112,21 @@ func runSync(cmd *cobra.Command, args []string) error { os.Exit(1) } + if enterpriseEnv == "DEFAULT" { + apiURL = enterpriseGatewayURL + } + if enterpriseEnv == "DEV" { + apiURL = enterpriseDevGatewayURL + } + if enterpriseEnv != "" && apiURL == "" { + fmt.Fprintf(os.Stderr, "Error: --enterprise accepts no value or =DEV, got %q\n", enterpriseEnv) + os.Exit(1) + } if apiURL == "" { apiURL = os.Getenv("UIGRAPH_GATEWAY_URL") } if apiURL == "" { - fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --api-url or UIGRAPH_GATEWAY_URL environment variable)") + fmt.Fprintln(os.Stderr, "Error: gateway URL is required (set --enterprise, --api-url or UIGRAPH_GATEWAY_URL environment variable)") os.Exit(1) }