-
Notifications
You must be signed in to change notification settings - Fork 6
feat(cmd): add info command to list supported agents and runtimes #121
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
+753
−16
Merged
Changes from all commits
Commits
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
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
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
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
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
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,128 @@ | ||
| /********************************************************************** | ||
| * Copyright (C) 2026 Red Hat, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| **********************************************************************/ | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| api "github.com/kortex-hub/kortex-cli-api/cli/go" | ||
| "github.com/kortex-hub/kortex-cli/pkg/runtimesetup" | ||
| "github.com/kortex-hub/kortex-cli/pkg/version" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // infoCmd contains the configuration for the info command | ||
| type infoCmd struct { | ||
| output string | ||
| } | ||
|
|
||
| // preRun validates the parameters and flags | ||
| func (i *infoCmd) preRun(cmd *cobra.Command, args []string) error { | ||
| // Validate output format if specified | ||
| if i.output != "" && i.output != "json" { | ||
| return fmt.Errorf("unsupported output format: %s (supported: json)", i.output) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
feloy marked this conversation as resolved.
Show resolved
Hide resolved
feloy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // run executes the info command logic | ||
| func (i *infoCmd) run(cmd *cobra.Command, args []string) error { | ||
| runtimes := runtimesetup.ListAvailable() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
||
| // Discover agents from runtimes that implement AgentLister | ||
| storageDir, err := cmd.Flags().GetString("storage") | ||
| if err != nil { | ||
| return outputErrorIfJSON(cmd, i.output, fmt.Errorf("failed to read --storage flag: %w", err)) | ||
| } | ||
|
|
||
| absStorageDir, err := filepath.Abs(storageDir) | ||
| if err != nil { | ||
| return outputErrorIfJSON(cmd, i.output, fmt.Errorf("failed to resolve storage directory path: %w", err)) | ||
| } | ||
|
|
||
| runtimeStorageDir := filepath.Join(absStorageDir, "runtimes") | ||
| agents, err := runtimesetup.ListAgents(runtimeStorageDir) | ||
| if err != nil { | ||
| return outputErrorIfJSON(cmd, i.output, fmt.Errorf("failed to list agents: %w", err)) | ||
| } | ||
|
|
||
| if i.output == "json" { | ||
| return i.outputJSON(cmd, agents, runtimes) | ||
| } | ||
|
|
||
| // Text output | ||
| out := cmd.OutOrStdout() | ||
| fmt.Fprintf(out, "Version: %s\n", version.Version) | ||
| fmt.Fprintf(out, "Agents: %s\n", strings.Join(agents, ", ")) | ||
| fmt.Fprintf(out, "Runtimes: %s\n", strings.Join(runtimes, ", ")) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // outputJSON outputs the info response as JSON | ||
| func (i *infoCmd) outputJSON(cmd *cobra.Command, agents, runtimes []string) error { | ||
| if agents == nil { | ||
| agents = []string{} | ||
| } | ||
| if runtimes == nil { | ||
| runtimes = []string{} | ||
| } | ||
| response := api.Info{ | ||
| Version: version.Version, | ||
| Agents: agents, | ||
| Runtimes: runtimes, | ||
| } | ||
|
|
||
| jsonData, err := json.MarshalIndent(response, "", " ") | ||
| if err != nil { | ||
| return outputErrorIfJSON(cmd, i.output, fmt.Errorf("failed to marshal info to JSON: %w", err)) | ||
| } | ||
|
|
||
| fmt.Fprintln(cmd.OutOrStdout(), string(jsonData)) | ||
| return nil | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func NewInfoCmd() *cobra.Command { | ||
| c := &infoCmd{} | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "info", | ||
| Short: "Display information about kortex-cli", | ||
| Example: `# Show info | ||
| kortex-cli info | ||
|
|
||
| # Show info in JSON format | ||
| kortex-cli info --output json | ||
|
|
||
| # Show info using short flag | ||
| kortex-cli info -o json`, | ||
| Args: cobra.NoArgs, | ||
| PreRunE: c.preRun, | ||
| RunE: c.run, | ||
| } | ||
|
|
||
| cmd.Flags().StringVarP(&c.output, "output", "o", "", "Output format (supported: json)") | ||
| cmd.RegisterFlagCompletionFunc("output", newOutputFlagCompletion([]string{"json"})) | ||
|
|
||
| return cmd | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.