-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simplified `tui` package * refactored most internals to be more resilient and testable * greatly expanded test coverage * aligned naming of various types across the codebase
- Loading branch information
Showing
136 changed files
with
1,125 additions
and
820 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
}, | ||
"cSpell.words": [ | ||
"bitmask", | ||
"Printfln", | ||
"Upsert", | ||
"upserter" | ||
] | ||
|
This file contains 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 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
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
cmd/disable/tests/disable-a-key-already-disabled/stderr.golden
This file contains 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,2 @@ | ||
---- exec command line 0: [disable KEY_B] | ||
WARNING: The key [ KEY_B ] is already disabled |
2 changes: 2 additions & 0 deletions
2
cmd/disable/tests/disable-a-key-already-disabled/stdout.golden
This file contains 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,2 @@ | ||
---- exec command line 0: [disable KEY_B] | ||
(no output to stdout) |
This file contains 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 @@ | ||
---- exec command line 0: [disable KEY_B] |
This file contains 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,2 @@ | ||
---- exec command line 0: [disable KEY_B] | ||
Key [ KEY_B ] was successfully disabled |
This file contains 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,6 @@ | ||
KEY_A="I'm key A" | ||
|
||
# Comment for KEY_B | ||
KEY_B="I'm key B" | ||
|
||
KEY_C="I'm key C" |
File renamed without changes.
File renamed without changes.
This file contains 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,2 @@ | ||
---- exec command line 0: [disable KEY_B] | ||
(no output to stderr) |
This file contains 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,2 @@ | ||
---- exec command line 0: [disable KEY_B] | ||
Key [ KEY_B ] was successfully disabled |
File renamed without changes.
This file contains 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 +1,3 @@ | ||
Could not find KEY [NONEXISTING_KEY] | ||
---- exec command line 0: [disable NONEXISTING_KEY] | ||
Error: Could not find KEY [ NONEXISTING_KEY ] | ||
Run 'dottie disable --help' for usage. |
This file contains 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,2 @@ | ||
---- exec command line 0: [disable NONEXISTING_KEY] | ||
(no output to stdout) |
File renamed without changes.
This file contains 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 +1,3 @@ | ||
Missing required argument: KEY | ||
---- exec command line 0: [disable] | ||
Error: accepts 1 arg(s), received 0 | ||
Run 'dottie disable --help' for usage. |
This file contains 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,2 @@ | ||
---- exec command line 0: [disable] | ||
(no output to stdout) |
This file contains 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,43 +1,52 @@ | ||
package enable | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/jippi/dottie/pkg" | ||
"github.com/jippi/dottie/pkg/cli/shared" | ||
"github.com/jippi/dottie/pkg/render" | ||
"github.com/jippi/dottie/pkg/tui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "enable KEY", | ||
Short: "Enable (uncomment) a KEY if it exists", | ||
Args: cobra.ExactArgs(1), | ||
GroupID: "manipulate", | ||
ValidArgsFunction: shared.NewCompleter().WithHandlers(render.ExcludeActiveAssignments).Get(), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
return errors.New("Missing required argument: KEY") | ||
} | ||
|
||
filename := cmd.Flag("file").Value.String() | ||
|
||
env, err := pkg.Load(filename) | ||
document, err := pkg.Load(filename) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
key := args[0] | ||
key := cmd.Flags().Arg(0) | ||
|
||
assignment := document.Get(key) | ||
if assignment == nil { | ||
return fmt.Errorf("Could not find KEY [ %s ]", key) | ||
} | ||
|
||
if assignment.Enabled { | ||
tui.MaybePrintWarnings(cmd.Context(), fmt.Errorf("The key [ %s ] is already enabled", key)) | ||
} | ||
|
||
assignment.Enable() | ||
|
||
existing := env.Get(key) | ||
if existing == nil { | ||
return fmt.Errorf("Could not find KEY [%s]", key) | ||
if err := pkg.Save(cmd.Context(), filename, document); err != nil { | ||
return fmt.Errorf("could not save file: %w", err) | ||
} | ||
|
||
existing.Enable() | ||
tui.StdoutFromContext(cmd.Context()). | ||
Success(). | ||
Printfln("Key [ %s ] was successfully enabled", key) | ||
|
||
return pkg.Save(filename, env) | ||
return nil | ||
}, | ||
} | ||
} |
This file contains 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
File renamed without changes.
This file contains 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,2 @@ | ||
---- exec command line 0: [enable KEY_B] | ||
WARNING: The key [ KEY_B ] is already enabled |
This file contains 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,2 @@ | ||
---- exec command line 0: [enable KEY_B] | ||
Key [ KEY_B ] was successfully enabled |
File renamed without changes.
This file contains 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,2 @@ | ||
---- exec command line 0: [enable KEY_B] | ||
(no output to stderr) |
This file contains 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,2 @@ | ||
---- exec command line 0: [enable KEY_B] | ||
Key [ KEY_B ] was successfully enabled |
File renamed without changes.
This file contains 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 +1,3 @@ | ||
Could not find KEY [NONEXISTING_KEY] | ||
---- exec command line 0: [enable NONEXISTING_KEY] | ||
Error: Could not find KEY [ NONEXISTING_KEY ] | ||
Run 'dottie enable --help' for usage. |
This file contains 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,2 @@ | ||
---- exec command line 0: [enable NONEXISTING_KEY] | ||
(no output to stdout) |
File renamed without changes.
This file contains 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 +1,3 @@ | ||
Missing required argument: KEY | ||
---- exec command line 0: [enable] | ||
Error: accepts 1 arg(s), received 0 | ||
Run 'dottie enable --help' for usage. |
This file contains 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,2 @@ | ||
---- exec command line 0: [enable] | ||
(no output to stdout) |
This file contains 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 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 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
File renamed without changes.
This file contains 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,2 @@ | ||
---- exec command line 0: [groups] | ||
(no output to stderr) |
This file contains 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,9 @@ | ||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ | ||
│ │ | ||
│ Groups in tests/multiple-groups.env │ | ||
│ │ | ||
└──────────────────────────────────────────────────────────────────────────────────────────────────┘ | ||
---- exec command line 0: [groups] | ||
┌──────────────────────────────────────────────────────────────────────────────┐ | ||
│ │ | ||
│ Groups in tests/multiple-groups.env │ | ||
│ │ | ||
└──────────────────────────────────────────────────────────────────────────────┘ | ||
my-first-group (tests/multiple-groups.env:2) | ||
my-second-group (tests/multiple-groups.env:13) | ||
my-third-group (tests/multiple-groups.env:17) |
File renamed without changes.
This file contains 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 +1,3 @@ | ||
No groups found | ||
---- exec command line 0: [groups] | ||
Error: No groups found | ||
Run 'dottie groups --help' for usage. |
This file contains 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,2 @@ | ||
---- exec command line 0: [groups] | ||
(no output to stdout) |
File renamed without changes.
This file contains 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,2 @@ | ||
---- exec command line 0: [groups] | ||
(no output to stderr) |
This file contains 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,6 +1,7 @@ | ||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ | ||
│ │ | ||
│ Groups in tests/single-group.env │ | ||
│ │ | ||
└──────────────────────────────────────────────────────────────────────────────────────────────────┘ | ||
---- exec command line 0: [groups] | ||
┌──────────────────────────────────────────────────────────────────────────────┐ | ||
│ │ | ||
│ Groups in tests/single-group.env │ | ||
│ │ | ||
└──────────────────────────────────────────────────────────────────────────────┘ | ||
my-group (tests/single-group.env:2) |
This file contains 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.