Skip to content
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ jobs:
- name: ⏬ Install Dependencies
run: go get .

- name: ⬇️ Fetch `env.reference.yaml` from `ws-meta`
run: |
curl -fsSL \
https://raw.githubusercontent.com/kloudkit/ws-meta/main/shared/workspace/env.reference.yaml \
-o "${{ runner.temp }}/env.reference.yaml"

- name: 🧪 Test
env:
WS__INTERNAL_ENV_REFERENCE: ${{ runner.temp }}/env.reference.yaml
run: go test -v ./...

- name: 👷‍♂️ Build for ${{ matrix.arch }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CLAUDE.md

ws-cli

/build
Expand Down
25 changes: 0 additions & 25 deletions CLAUDE.md

This file was deleted.

5 changes: 3 additions & 2 deletions cmd/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package feature

import (
"github.com/kloudkit/ws-cli/internals/config"
"github.com/kloudkit/ws-cli/internals/env"
"github.com/spf13/cobra"
)

Expand All @@ -12,9 +11,11 @@ var FeatureCmd = &cobra.Command{
}

func init() {
root, _ := config.Resolve("features", "dir")

FeatureCmd.PersistentFlags().String(
"root",
env.String(config.EnvFeaturesDir, config.DefaultFeaturesDir),
root,
"Root directory of additional features",
)

Expand Down
3 changes: 1 addition & 2 deletions cmd/feature/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/kloudkit/ws-cli/internals/config"
"github.com/kloudkit/ws-cli/internals/env"
"github.com/kloudkit/ws-cli/internals/features"
"github.com/kloudkit/ws-cli/internals/styles"
"github.com/spf13/cobra"
Expand All @@ -14,7 +13,7 @@ var storeCmd = &cobra.Command{
Use: "store",
Short: "List packages available in the feature store",
RunE: func(cmd *cobra.Command, args []string) error {
storeURL := env.String(config.EnvFeaturesStoreURL)
storeURL, _ := config.Resolve("features", "store_url")
if storeURL == "" {
styles.PrintWarning(cmd.OutOrStdout(), "Feature store not configured (set WS_FEATURES_STORE_URL)")
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/info/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package info

var Version = "0.0.50"
var Version = "0.0.51"
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/kloudkit/ws-cli/cmd/serve"
"github.com/kloudkit/ws-cli/cmd/show"
"github.com/kloudkit/ws-cli/cmd/template"
"github.com/kloudkit/ws-cli/internals/config"
"github.com/kloudkit/ws-cli/internals/styles"
"github.com/spf13/cobra"
)
Expand All @@ -24,6 +25,13 @@ var rootCmd = &cobra.Command{
Version: "v" + info.Version,
Aliases: []string{"ws"},
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := config.RequireWorkspace(); err != nil {
return err
}
_, err := config.LoadEnvReference()
return err
},
}

func Execute() {
Expand Down
122 changes: 122 additions & 0 deletions cmd/show/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package show

import (
"fmt"
"os"

"github.com/kloudkit/ws-cli/internals/config"
"github.com/kloudkit/ws-cli/internals/styles"
"github.com/spf13/cobra"
)

var osExit = os.Exit

var envCmd = &cobra.Command{
Use: "env <KEY>",
Short: "Display the resolved value of a workspace environment variable",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
key := args[0]

asList, _ := cmd.Flags().GetBool("list")
asBool, _ := cmd.Flags().GetBool("bool")
asInt, _ := cmd.Flags().GetBool("int")
asCheck, _ := cmd.Flags().GetBool("check")
raw, _ := cmd.Flags().GetBool("raw")
delimiter, _ := cmd.Flags().GetString("delimiter")
deprecated, _ := cmd.Flags().GetString("deprecated")

switch {
case asCheck:
return runCheck(cmd, key, deprecated)
case asBool:
return runBool(cmd, key)
case asInt:
return runInt(cmd, key)
case asList:
return runList(cmd, key, delimiter)
}

value, err := config.ResolveKey(key)
if err != nil {
return err
}

if styles.OutputRaw(cmd.OutOrStdout(), raw, value) {
return nil
}

styles.PrintTitle(cmd.OutOrStdout(), "Workspace Environment")
styles.PrintKeyCode(cmd.OutOrStdout(), key, value)

return nil
},
}

func runCheck(cmd *cobra.Command, preferred, deprecated string) error {
switch config.Check(preferred, deprecated) {
case config.CheckPreferredSet:
return nil
case config.CheckDeprecatedOnly:
fmt.Fprintln(cmd.ErrOrStderr(), config.DeprecationLine(deprecated, preferred))
osExit(1)
case config.CheckBothSet:
fmt.Fprintln(cmd.ErrOrStderr(), config.BothSetLine(deprecated, preferred))
osExit(2)
case config.CheckUnset:
osExit(1)
}
return nil
}

func runBool(_ *cobra.Command, key string) error {
value, err := config.ResolveKey(key)
if err != nil {
return err
}
parsed, err := config.ParseBool(value)
if err != nil {
return err
}
if !parsed {
osExit(1)
}
return nil
}

func runInt(cmd *cobra.Command, key string) error {
value, err := config.ResolveKey(key)
if err != nil {
return err
}
parsed, err := config.ParseInt(value)
if err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), parsed)
return nil
}

func runList(cmd *cobra.Command, key, delimiter string) error {
items, err := config.ResolveListKey(key, delimiter)
if err != nil {
return err
}
for _, item := range items {
fmt.Fprintln(cmd.OutOrStdout(), item)
}
return nil
}

func init() {
envCmd.Flags().Bool("list", false, "Output as newline-separated list (uses YAML delimiter or --delimiter)")
envCmd.Flags().Bool("bool", false, "Coerce to boolean; exit 0 truthy, 1 falsy, 2 invalid")
envCmd.Flags().Bool("int", false, "Coerce to integer; print canonical form or fail with exit 2")
envCmd.Flags().Bool("check", false, "Check whether the variable (or its --deprecated alias) is set")
envCmd.Flags().String("delimiter", "", "Override delimiter for --list (defaults to YAML delimiter or space)")
envCmd.Flags().String("deprecated", "", "Deprecated alias paired with --check")

envCmd.MarkFlagsMutuallyExclusive("list", "bool", "int", "check")

ShowCmd.AddCommand(envCmd)
}
3 changes: 1 addition & 2 deletions cmd/show/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package show

import (
"github.com/kloudkit/ws-cli/internals/config"
"github.com/kloudkit/ws-cli/internals/env"
"github.com/kloudkit/ws-cli/internals/path"
"github.com/kloudkit/ws-cli/internals/styles"
"github.com/spf13/cobra"
Expand All @@ -17,7 +16,7 @@ var pathHomeCmd = &cobra.Command{
Use: "home",
Short: "Display the workspace home path",
RunE: func(cmd *cobra.Command, args []string) error {
homePath := env.String(config.EnvServerRoot, config.DefaultServerRoot)
homePath := config.MustResolve("server", "root")

raw, _ := cmd.Flags().GetBool("raw")
if styles.OutputRaw(cmd.OutOrStdout(), raw, homePath) {
Expand Down
Loading
Loading