-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add furyctl get aliases command for tool management
#618
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
Draft
nutellinoit
wants to merge
11
commits into
main
Choose a base branch
from
feat/aliases-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c86d80
feat: add comprehensive tools management system
nutellinoit 37b11d0
fix: clarify aliases command description to focus on distribution com…
nutellinoit bf958e2
fix: use existing file permissions constant from internal/x/io
nutellinoit 5f23313
fix: correct mise.toml filename in tools command description
nutellinoit 612be3d
feat: add configurable mise file path with --mise-file flag
nutellinoit 96c12a6
feat: implement proper section order preservation in mise.toml
nutellinoit 24ee0f6
fix: remove log level suppression to respect user's debug settings
nutellinoit a62080a
fix: revert get command description to original wording
nutellinoit db6f8d1
fix: update mise test calls to include miseFile parameter
nutellinoit 5f716e1
Fix linting issues in mise.go
nutellinoit 33990e6
Fix linting issues in shared.go
nutellinoit 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Copyright (c) 2017-present SIGHUP s.r.l All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/sighupio/furyctl/cmd/tools" | ||
| ) | ||
|
|
||
| func NewToolsCmd() *cobra.Command { | ||
| toolsCmd := &cobra.Command{ | ||
| Use: "tools", | ||
| Short: "Manage tool integrations for downloaded binaries", | ||
| Long: `Manage tool integrations for downloaded binaries. | ||
|
|
||
| Generate various output formats for integrating furyctl-downloaded tools | ||
| with your shell environment. Choose the format that works best with your | ||
| development setup: | ||
|
|
||
| - aliases: Traditional bash aliases (default) | ||
| - functions: Bash functions that override version managers like mise/asdf | ||
| - mise: Native mise integration via mise.toml file`, | ||
| } | ||
|
|
||
| toolsCmd.AddCommand(tools.NewAliasesCmd()) | ||
| toolsCmd.AddCommand(tools.NewFunctionsCmd()) | ||
| toolsCmd.AddCommand(tools.NewMiseCmd()) | ||
|
|
||
| return toolsCmd | ||
| } |
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,34 @@ | ||
| // Copyright (c) 2017-present SIGHUP s.r.l All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package tools | ||
|
|
||
| import "github.com/spf13/cobra" | ||
|
|
||
| // NewAliasesCmd creates the aliases command. | ||
| func NewAliasesCmd() *cobra.Command { | ||
| return CreateShellIntegrationCommand( | ||
| "aliases", | ||
| "Generate bash aliases for downloaded tools", | ||
| `Generate bash aliases for tools downloaded by furyctl. | ||
|
|
||
| This command outputs bash aliases that point to the downloaded tool binaries | ||
| with versions that are compatible with your SIGHUP Distribution configuration. | ||
|
|
||
| Examples: | ||
| # View aliases | ||
| furyctl tools aliases | ||
|
|
||
| # Set aliases in current session | ||
| eval "$(furyctl tools aliases)" | ||
|
|
||
| # Add to your shell profile | ||
| furyctl tools aliases >> ~/.bashrc | ||
|
|
||
| # Use the tools natively | ||
| kubectl --help | ||
| helm list --help`, | ||
| AliasFormat, | ||
| ) | ||
| } |
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,113 @@ | ||
| // Copyright (c) 2017-present SIGHUP s.r.l All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package tools_test | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/sighupio/furyctl/cmd/tools" | ||
| ) | ||
|
|
||
| func TestNewAliasesCmd(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cmd := tools.NewAliasesCmd() | ||
|
|
||
| assert.Equal(t, "aliases", cmd.Use) | ||
| assert.Equal(t, "Generate bash aliases for downloaded tools", cmd.Short) | ||
| assert.Contains(t, cmd.Long, "Generate bash aliases for tools downloaded by furyctl") | ||
| assert.Contains(t, cmd.Long, "eval \"$(furyctl tools aliases)\"") | ||
| } | ||
|
|
||
| func TestAliasesCmd_FlagValidation(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cmd := tools.NewAliasesCmd() | ||
|
|
||
| // Test that command can be created and has expected flags. | ||
| assert.NotNil(t, cmd) | ||
|
|
||
| // Verify required flags exist. | ||
| configFlag := cmd.Flags().Lookup("config") | ||
| assert.NotNil(t, configFlag) | ||
| assert.Equal(t, "furyctl.yaml", configFlag.DefValue) | ||
|
|
||
| binPathFlag := cmd.Flags().Lookup("bin-path") | ||
| assert.NotNil(t, binPathFlag) | ||
|
|
||
| skipDepsFlag := cmd.Flags().Lookup("skip-deps-download") | ||
| assert.NotNil(t, skipDepsFlag) | ||
| assert.Equal(t, "false", skipDepsFlag.DefValue) | ||
| } | ||
|
|
||
| func TestAliasesCmd_CommandStructure(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cmd := tools.NewAliasesCmd() | ||
|
|
||
| // Verify the command is properly structured. | ||
| assert.NotNil(t, cmd.PreRun) | ||
| assert.NotNil(t, cmd.RunE) | ||
|
|
||
| // Check flags are properly defined. | ||
| binPathFlag := cmd.Flags().Lookup("bin-path") | ||
| assert.NotNil(t, binPathFlag) | ||
| assert.Equal(t, "b", binPathFlag.Shorthand) | ||
|
|
||
| configFlag := cmd.Flags().Lookup("config") | ||
| assert.NotNil(t, configFlag) | ||
| assert.Equal(t, "c", configFlag.Shorthand) | ||
| assert.Equal(t, "furyctl.yaml", configFlag.DefValue) | ||
|
|
||
| skipDepsFlag := cmd.Flags().Lookup("skip-deps-download") | ||
| assert.NotNil(t, skipDepsFlag) | ||
| assert.Equal(t, "false", skipDepsFlag.DefValue) | ||
| } | ||
|
|
||
| func TestAliasesOutput_Format(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Test the expected alias format. | ||
| toolName := "kubectl" | ||
| toolPath := "/path/to/.furyctl/bin/kubectl/1.25.8/kubectl" | ||
|
|
||
| expectedAlias := `alias kubectl="/path/to/.furyctl/bin/kubectl/1.25.8/kubectl"` | ||
|
|
||
| // Simulate the alias generation format. | ||
| actualAlias := "alias " + toolName + "=\"" + toolPath + "\"" | ||
|
|
||
| assert.Equal(t, expectedAlias, actualAlias) | ||
| } | ||
|
|
||
| func TestAliasesOutput_MultipleTools(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Test multiple aliases format. | ||
| tools := []struct { | ||
| name string | ||
| path string | ||
| }{ | ||
| {"kubectl", "/path/to/.furyctl/bin/kubectl/1.25.8/kubectl"}, | ||
| {"helm", "/path/to/.furyctl/bin/helm/3.10.0/helm"}, | ||
| {"terraform", "/path/to/.furyctl/bin/terraform/1.5.7/terraform"}, | ||
| } | ||
|
|
||
| aliases := make([]string, 0, len(tools)) | ||
|
|
||
| for _, tool := range tools { | ||
| alias := "alias " + tool.name + "=\"" + tool.path + "\"" | ||
| aliases = append(aliases, alias) | ||
| } | ||
|
|
||
| output := strings.Join(aliases, "\n") | ||
|
|
||
| assert.Contains(t, output, "alias kubectl=") | ||
| assert.Contains(t, output, "alias helm=") | ||
| assert.Contains(t, output, "alias terraform=") | ||
| assert.Len(t, strings.Split(output, "\n"), 3) | ||
| } | ||
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,34 @@ | ||
| // Copyright (c) 2017-present SIGHUP s.r.l All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package tools | ||
|
|
||
| import "github.com/spf13/cobra" | ||
|
|
||
| // NewFunctionsCmd creates the functions command. | ||
| func NewFunctionsCmd() *cobra.Command { | ||
| return CreateShellIntegrationCommand( | ||
| "functions", | ||
| "Generate bash functions for downloaded tools", | ||
| `Generate bash functions for tools downloaded by furyctl. | ||
|
|
||
| This command generates bash functions instead of aliases. Functions have higher | ||
| precedence than aliases and will override version managers like mise, asdf, or | ||
| other tools that create aliases. | ||
|
|
||
| Use this when you have version managers installed but want furyctl-downloaded | ||
| tools to take precedence. | ||
|
|
||
| Examples: | ||
| # View functions | ||
| furyctl tools functions | ||
|
|
||
| # Set functions in current session (overrides mise/asdf) | ||
| eval "$(furyctl tools functions)" | ||
|
|
||
| # Add to your shell profile | ||
| furyctl tools functions >> ~/.bashrc`, | ||
| FunctionFormat, | ||
| ) | ||
| } |
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.
not sure how much this kind of test makes sense. it's testing more cobra than our actual code, a better test would be to actually use test the flags in the actual code