diff options
| author | Fuwn <[email protected]> | 2024-10-23 06:05:05 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-23 06:05:05 -0700 |
| commit | 49e21d633c14f639659c8ec3312bb808dec3005e (patch) | |
| tree | 0d0f65a11910081f7036859ee028fe9a6dc49cfd | |
| parent | cb482154c1c9647d747cc15314f424d7be606569 (diff) | |
| download | yae-49e21d633c14f639659c8ec3312bb808dec3005e.tar.xz yae-49e21d633c14f639659c8ec3312bb808dec3005e.zip | |
feat(yae): dry-run flag
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | internal/commands/add.go | 4 | ||||
| -rw-r--r-- | internal/commands/drop.go | 4 | ||||
| -rw-r--r-- | internal/commands/init.go | 4 | ||||
| -rw-r--r-- | internal/commands/update.go | 2 | ||||
| -rw-r--r-- | yae.go | 4 |
6 files changed, 20 insertions, 1 deletions
@@ -200,6 +200,9 @@ COMMANDS: GLOBAL OPTIONS: --sources value Sources path (default: "./yae.json") + --debug Enable debug output (default: false) + --silent Silence log output (default: false) + --dry-run Prevents writing to disk (default: false) --help, -h show help COPYRIGHT: diff --git a/internal/commands/add.go b/internal/commands/add.go index e32d07d..1b32533 100644 --- a/internal/commands/add.go +++ b/internal/commands/add.go @@ -107,6 +107,10 @@ func Add(sources *yae.Sources) func(c *cli.Context) error { return err } + if c.Bool("dry-run") { + return nil + } + return sources.Save(c.String("sources")) } } diff --git a/internal/commands/drop.go b/internal/commands/drop.go index 58855df..f30afb6 100644 --- a/internal/commands/drop.go +++ b/internal/commands/drop.go @@ -19,6 +19,10 @@ func Drop(sources *yae.Sources) func(c *cli.Context) error { sources.Drop(c.Args().Get(0)) + if c.Bool("dry-run") { + return nil + } + return sources.Save(c.String("sources")) } } diff --git a/internal/commands/init.go b/internal/commands/init.go index f38ec96..4d41553 100644 --- a/internal/commands/init.go +++ b/internal/commands/init.go @@ -14,6 +14,10 @@ func Init(sources *yae.Sources) func(c *cli.Context) error { return fmt.Errorf("sources file already exists") } + if c.Bool("dry-run") { + return nil + } + return sources.Save(c.String("sources")) } } diff --git a/internal/commands/update.go b/internal/commands/update.go index b1ce17b..fa7e09f 100644 --- a/internal/commands/update.go +++ b/internal/commands/update.go @@ -53,7 +53,7 @@ func Update(sources *yae.Sources) func(c *cli.Context) error { } } - if len(updates) > 0 { + if len(updates) > 0 && !c.Bool("dry-run") { if err := sources.Save(c.String("sources")); err != nil { return err } @@ -65,6 +65,10 @@ func main() { return nil }, }, + &cli.BoolFlag{ + Name: "dry-run", + Usage: "Prevents writing to disk", + }, }, Copyright: fmt.Sprintf("Copyright (c) 2024-%s Fuwn", fmt.Sprint(time.Now().Year())), ExitErrHandler: func(c *cli.Context, err error) { |