Skip to content

Commit

Permalink
reorgnize command names into their own folders
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Feb 9, 2024
1 parent 638ddd5 commit f85ec9a
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 127 deletions.
19 changes: 0 additions & 19 deletions cmd/cmd_fmt.go

This file was deleted.

25 changes: 0 additions & 25 deletions cmd/cmd_json.go

This file was deleted.

22 changes: 0 additions & 22 deletions cmd/cmd_print.go

This file was deleted.

14 changes: 9 additions & 5 deletions cmd/cmd_disable.go → cmd/disable/disable.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package main
package disable

import (
"context"

"github.com/jippi/dottie/pkg"

"github.com/jippi/dottie/pkg/cli/shared"
"github.com/urfave/cli/v3"
)

var disableCommand = &cli.Command{
var Command = &cli.Command{
Name: "disable",
Usage: "Comment/disable a key if it exists",
Before: setup,
ArgsUsage: "KEY",
Action: func(_ context.Context, cmd *cli.Command) error {
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

key := cmd.Args().Get(0)
existing := env.Get(key)
existing.Active = false
Expand Down
14 changes: 9 additions & 5 deletions cmd/cmd_enable.go → cmd/enable/enable.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package main
package enable

import (
"context"

"github.com/jippi/dottie/pkg"

"github.com/jippi/dottie/pkg/cli/shared"
"github.com/urfave/cli/v3"
)

var enableCommand = &cli.Command{
var Command = &cli.Command{
Name: "enable",
Usage: "Uncomment/enable a key if it exists",
Before: setup,
ArgsUsage: "KEY",
Action: func(_ context.Context, cmd *cli.Command) error {
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

key := cmd.Args().Get(0)

existing := env.Get(key)
Expand Down
24 changes: 24 additions & 0 deletions cmd/fmt/fmt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fmt

import (
"context"

"github.com/jippi/dottie/pkg"
"github.com/jippi/dottie/pkg/cli/shared"
"github.com/urfave/cli/v3"
)

var Command = &cli.Command{
Name: "fmt",
Usage: "Format the file",
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

pkg.Save(cmd.String("file"), env)

return nil
},
}
17 changes: 11 additions & 6 deletions cmd/cmd_groups.go → cmd/groups/groups.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package main
package groups

import (
"context"
"fmt"

"github.com/gosimple/slug"
"github.com/jippi/dottie/pkg/cli/shared"
"github.com/urfave/cli/v3"
)

var groupsCommand = &cli.Command{
Name: "groups",
Usage: "Print groups found in the .env file",
Before: setup,
Action: func(_ context.Context, _ *cli.Command) error {
var Command = &cli.Command{
Name: "groups",
Usage: "Print groups found in the .env file",
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

groups := env.Groups
if len(groups) == 0 {
return fmt.Errorf("No groups found")
Expand Down
30 changes: 30 additions & 0 deletions cmd/json/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package json

import (
"context"
"encoding/json"
"fmt"

"github.com/jippi/dottie/pkg/cli/shared"
"github.com/urfave/cli/v3"
)

var Command = &cli.Command{
Name: "json",
Usage: "Print as JSON",
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

b, err := json.MarshalIndent(env, "", " ")
if err != nil {
return err
}

fmt.Println(string(b))

return nil
},
}
33 changes: 22 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import (

goversion "github.com/caarlos0/go-version"
"github.com/davecgh/go-spew/spew"
"github.com/jippi/dottie/cmd/disable"
"github.com/jippi/dottie/cmd/enable"
"github.com/jippi/dottie/cmd/fmt"
"github.com/jippi/dottie/cmd/groups"
"github.com/jippi/dottie/cmd/json"
print_cmd "github.com/jippi/dottie/cmd/print"
"github.com/jippi/dottie/cmd/set"
"github.com/jippi/dottie/cmd/update"
"github.com/jippi/dottie/cmd/validate"
"github.com/jippi/dottie/cmd/value"
"github.com/jippi/dottie/pkg/ast"
"github.com/jippi/dottie/pkg/cli/shared"
"github.com/jippi/dottie/pkg/render"
"github.com/urfave/cli/v3"
)
Expand Down Expand Up @@ -48,18 +59,18 @@ func main() {
Suggest: true,
EnableShellCompletion: true,
ShellCompletionCommandName: "completions",
Flags: globalFlags,
Flags: shared.GlobalFlags,
Commands: []*cli.Command{
disableCommand,
enableCommand,
groupsCommand,
formatCmd,
jsonCommand,
printCommand,
setCommand,
updateCommand,
validateCommand,
valueCommand,
disable.Command,
enable.Command,
fmt.Command,
groups.Command,
json.Command,
print_cmd.Command,
set.Command,
update.Command,
validate.Command,
value.Command,
},
}

Expand Down
27 changes: 27 additions & 0 deletions cmd/print/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package print_cmd

import (
"context"
"fmt"

"github.com/jippi/dottie/pkg/cli/shared"
"github.com/jippi/dottie/pkg/render"
"github.com/urfave/cli/v3"
)

var Command = &cli.Command{
Name: "print",
Usage: "Print environment variables",
Action: func(ctx context.Context, cmd *cli.Command) error {
env, settings, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

settings.Apply(render.WithInterpolation(true))

fmt.Println(render.NewRenderer(*settings).Statement(env).String())

return nil
},
}
14 changes: 9 additions & 5 deletions cmd/cmd_set.go → cmd/set/set.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package set

import (
"context"
Expand All @@ -7,18 +7,17 @@ import (

"github.com/jippi/dottie/pkg"
"github.com/jippi/dottie/pkg/ast"
"github.com/jippi/dottie/pkg/cli/shared"
"github.com/jippi/dottie/pkg/token"
"github.com/jippi/dottie/pkg/tui"
"github.com/jippi/dottie/pkg/validation"

"github.com/urfave/cli/v3"
)

var setCommand = &cli.Command{
var Command = &cli.Command{
Name: "set",
Usage: "Set/update one or multiple key=value pairs",
UsageText: "set KEY=VALUE [KEY=VALUE ...]",
Before: setup,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "disabled",
Expand Down Expand Up @@ -71,7 +70,12 @@ var setCommand = &cli.Command{
Usage: "Set one or multiple lines of comments to the KEY=VALUE pair",
},
},
Action: func(_ context.Context, cmd *cli.Command) error {
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

if cmd.Args().Len() == 0 {
return fmt.Errorf("Missing required argument: KEY=VALUE")
}
Expand Down
20 changes: 12 additions & 8 deletions cmd/cmd_update.go → cmd/update/update.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package update

import (
"context"
Expand All @@ -7,18 +7,22 @@ import (
"io"
"os"

"github.com/hashicorp/go-getter"
"github.com/jippi/dottie/pkg"
"github.com/jippi/dottie/pkg/ast"

"github.com/hashicorp/go-getter"
"github.com/jippi/dottie/pkg/cli/shared"
"github.com/urfave/cli/v3"
)

var updateCommand = &cli.Command{
Name: "update",
Usage: "Update the .env file from a source",
Before: setup,
Action: func(_ context.Context, _ *cli.Command) error {
var Command = &cli.Command{
Name: "update",
Usage: "Update the .env file from a source",
Action: func(ctx context.Context, cmd *cli.Command) error {
env, _, err := shared.Setup(ctx, cmd)
if err != nil {
return err
}

fmt.Print("Finding source")
source, err := env.GetConfig("dottie/source")
if err != nil {
Expand Down
Loading

0 comments on commit f85ec9a

Please sign in to comment.