-
Notifications
You must be signed in to change notification settings - Fork 145
feat(cli): scaffold ossie CLI #151
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
dd67918
feat(cli): scaffold go module with cobra command tree
QMalcolm 260f721
chore(cli): add makefile and goreleaser build pipeline
QMalcolm e4a1fe6
ci(cli): add github actions workflow for build and test
QMalcolm 38d52c1
test(cli): add unit tests for internal/osidir
QMalcolm ef807ad
chore(cli): rename osi to ossie throughout cli scaffold
QMalcolm 44bcd44
chore(cli): rename internal osidir package to ossiedir
QMalcolm aa4f8d9
fix(ossiedir): rename defaultOSIDir constant to defaultOssieDir
QMalcolm 3106189
chore(cli): fix .gitignore to ignore cli/ossie build artifact
QMalcolm d86a250
chore(ossiedir): rename osidir.go and osidir_test.go to ossiedir
QMalcolm 782fb0c
Swap references to Open Semantic Interchange to Apache
QMalcolm b834d75
chore(cli): align go.mod version with .tool-versions pin
QMalcolm ccd7c55
refactor(cli): let cobra enforce --from/--to via MarkFlagsOneRequired
QMalcolm ea4b49c
Merge branch 'main' into qmalcolm--feat-cli-scaffold
QMalcolm b46aa7f
Apply suggestions from code review
khush-bhatia ed0a0ad
chore(cli): stop tracking .tool-versions, gitignore for local use
QMalcolm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: CLI CI | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - 'cli/**' | ||
| - '.github/workflows/cli-ci.yml' | ||
| pull_request: | ||
| paths: | ||
| - 'cli/**' | ||
| - '.github/workflows/cli-ci.yml' | ||
|
|
||
| jobs: | ||
| build-and-test: | ||
| name: Build and test | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: cli | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: cli/go.mod | ||
| cache-dependency-path: cli/go.sum | ||
|
|
||
| - name: go build | ||
| run: go build ./... | ||
|
|
||
| - name: go vet | ||
| run: go vet ./... | ||
|
|
||
| - name: go test | ||
| run: go test ./... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| **/__pycache__/ | ||
| **/.venv/ | ||
|
|
||
| **/.pytest_cache/ | ||
| **/.ruff_cache/ | ||
| **/.coverage | ||
| **/htmlcov/ | ||
| **/dist/ | ||
| **/target/ | ||
|
|
||
| # Go CLI | ||
| cli/dist/ | ||
| cli/ossie | ||
| cli/.tool-versions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| version: 2 | ||
|
|
||
| project_name: ossie | ||
|
|
||
| before: | ||
| hooks: | ||
| - go mod tidy | ||
|
|
||
| builds: | ||
| - id: ossie | ||
| main: . | ||
| binary: ossie | ||
| goos: | ||
| - linux | ||
| - darwin | ||
| - windows | ||
| goarch: | ||
| - amd64 | ||
| - arm64 | ||
| ignore: | ||
| - goos: windows | ||
| goarch: arm64 | ||
| env: | ||
| - CGO_ENABLED=0 | ||
| ldflags: | ||
| - -s -w | ||
| - -X main.version={{.Version}} | ||
| - -X main.commit={{.Commit}} | ||
| - -X main.date={{.Date}} | ||
|
|
||
| archives: | ||
| - id: ossie | ||
| format: tar.gz | ||
| format_overrides: | ||
| - goos: windows | ||
| format: zip | ||
| name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
|
|
||
| checksum: | ||
| name_template: "checksums.txt" | ||
|
|
||
| changelog: | ||
| sort: asc | ||
| filters: | ||
| exclude: | ||
| - "^docs:" | ||
| - "^test:" | ||
| - "^chore:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| BINARY_NAME := ossie | ||
| BUILD_DIR := dist | ||
|
|
||
| .PHONY: build test lint release-dry-run clean | ||
|
|
||
| build: | ||
| go build -o $(BUILD_DIR)/$(BINARY_NAME) . | ||
|
|
||
| test: | ||
| go test ./... | ||
|
|
||
| lint: | ||
| go vet ./... | ||
|
|
||
| release-dry-run: | ||
| goreleaser release --snapshot --clean --config .goreleaser.yaml | ||
|
|
||
| clean: | ||
| rm -rf $(BUILD_DIR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var convertCmd = &cobra.Command{ | ||
| Use: "convert --from <platform> --input <path> | --to <platform> --input <path>", | ||
| Short: "Convert a semantic model between Ossie and a platform format", | ||
| RunE: runConvert, | ||
| } | ||
|
|
||
| func init() { | ||
| convertCmd.Flags().String("from", "", "Source platform — converts platform → Ossie") | ||
| convertCmd.Flags().String("to", "", "Target platform — converts Ossie → platform") | ||
| convertCmd.Flags().StringP("input", "i", "", "Input file or directory path (required)") | ||
| convertCmd.Flags().StringP("output", "o", "", "Output directory path (default: ./ossie-output/<plugin>/<direction>)") | ||
| convertCmd.Flags().String("plugin", "", "Path to plugin directory (bypasses name-based discovery)") | ||
| convertCmd.Flags().Int("timeout", 60, "Plugin invocation timeout in seconds") | ||
| convertCmd.Flags().String("max-input-size", "100MB", "Maximum total input size (e.g. 500MB)") | ||
|
|
||
| _ = convertCmd.MarkFlagRequired("input") | ||
| convertCmd.MarkFlagsMutuallyExclusive("from", "to") | ||
| convertCmd.MarkFlagsOneRequired("from", "to") | ||
| } | ||
|
|
||
| func runConvert(cmd *cobra.Command, args []string) error { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "not yet implemented") | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package plugin | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var installCmd = &cobra.Command{ | ||
| Use: "install [name[@version] | url]", | ||
| Short: "Install a plugin from the registry or a URL", | ||
| RunE: runPluginInstall, | ||
| } | ||
|
|
||
| func init() { | ||
| installCmd.Flags().Bool("all", false, "Install the latest version of all registry plugins") | ||
| } | ||
|
|
||
| func runPluginInstall(cmd *cobra.Command, args []string) error { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "not yet implemented") | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package plugin | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var listCmd = &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List installed and available plugins", | ||
| RunE: runPluginList, | ||
| } | ||
|
|
||
| func runPluginList(cmd *cobra.Command, args []string) error { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "not yet implemented") | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package plugin | ||
|
|
||
| import "github.com/spf13/cobra" | ||
|
|
||
| // Cmd is the parent "ossie plugin" command. It is exported so cmd/root.go can | ||
| // register it. Invoking it bare prints help. | ||
| var Cmd = &cobra.Command{ | ||
| Use: "plugin", | ||
| Short: "Manage Ossie plugins", | ||
| } | ||
|
|
||
| func init() { | ||
| Cmd.AddCommand(listCmd) | ||
| Cmd.AddCommand(installCmd) | ||
| Cmd.AddCommand(removeCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package plugin | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var removeCmd = &cobra.Command{ | ||
| Use: "remove <name>", | ||
| Short: "Remove an installed plugin", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: runPluginRemove, | ||
| } | ||
|
|
||
| func runPluginRemove(cmd *cobra.Command, args []string) error { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "not yet implemented") | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/apache/ossie/cli/cmd/plugin" | ||
| "github.com/apache/ossie/cli/internal/ossiedir" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var rootCmd = &cobra.Command{ | ||
| Use: "ossie", | ||
| Short: "Apache Ossie (incubating) CLI", | ||
| Long: `ossie is the command-line tool for the Apache Ossie (incubating) project.`, | ||
| // NOTE: Cobra does NOT automatically chain PersistentPreRunE from parent to | ||
| // child. If any subcommand defines its own PersistentPreRunE or PreRunE, this | ||
| // function will not run for that subcommand. Future subcommands that define | ||
| // their own must call ossiedir.EnsurePluginDir() explicitly. | ||
| PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
| return ossiedir.EnsurePluginDir() | ||
| }, | ||
| } | ||
|
|
||
| // Execute runs the root command. Called by main. | ||
| func Execute() error { | ||
| return rootCmd.Execute() | ||
| } | ||
|
|
||
| // SetVersion sets the version string reported by `ossie --version`. | ||
| func SetVersion(v string) { | ||
| rootCmd.Version = v | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose output (shows plugin stderr)") | ||
|
|
||
| rootCmd.AddCommand(convertCmd) | ||
| rootCmd.AddCommand(validateCmd) | ||
| rootCmd.AddCommand(plugin.Cmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var validateCmd = &cobra.Command{ | ||
| Use: "validate [flags] <path> [<path>...]", | ||
| Short: "Validate one or more OSSIE YAML or JSON files", | ||
| Args: cobra.MinimumNArgs(1), | ||
| RunE: runValidate, | ||
| } | ||
|
|
||
| func init() { | ||
| validateCmd.Flags().Bool("strict", false, "Promote warnings to errors") | ||
| validateCmd.Flags().String("output", "text", "Output format: text or json") | ||
| } | ||
|
|
||
| func runValidate(cmd *cobra.Command, args []string) error { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "not yet implemented") | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module github.com/apache/ossie/cli | ||
|
|
||
| go 1.26.2 | ||
|
|
||
| require github.com/spf13/cobra v1.10.2 | ||
|
|
||
| require ( | ||
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| github.com/spf13/pflag v1.0.9 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= | ||
| github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
| github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
| github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
| github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= | ||
| github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= | ||
| github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= | ||
| github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
| go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package ossiedir | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultOssieDir = ".ossie" | ||
| pluginsSubdir = "plugins" | ||
| envVar = "OSSIE_PLUGIN_DIR" | ||
| ) | ||
|
|
||
| // PluginDir returns the resolved plugin directory path. | ||
| // It respects $OSSIE_PLUGIN_DIR if set, otherwise defaults to ~/.ossie/plugins/. | ||
| func PluginDir() (string, error) { | ||
| if override := os.Getenv(envVar); override != "" { | ||
| return override, nil | ||
| } | ||
| // Use os.UserHomeDir rather than $HOME for Windows portability. | ||
| home, err := os.UserHomeDir() | ||
| if err != nil { | ||
| return "", fmt.Errorf("could not determine home directory: %w", err) | ||
| } | ||
| return filepath.Join(home, defaultOssieDir, pluginsSubdir), nil | ||
| } | ||
|
|
||
| // EnsurePluginDir ensures the plugin directory exists, creating it if needed. | ||
| // It is safe to call multiple times — os.MkdirAll is idempotent. | ||
| func EnsurePluginDir() error { | ||
| dir, err := PluginDir() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := os.MkdirAll(dir, 0755); err != nil { | ||
| return fmt.Errorf("could not create plugin directory %s: %w", dir, err) | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for setting up the workflow for tests.