aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-10-13 01:14:49 -0700
committerFuwn <[email protected]>2024-10-13 01:14:49 -0700
commit4353451af2a6edeeca75f5a87186d40d5e81159a (patch)
treed3f8915a08a88f417056c2e005afe508e0484e1e
parent0aeae8d523ecb762e296b938cff3e012551e27b7 (diff)
downloadyae-4353451af2a6edeeca75f5a87186d40d5e81159a.tar.xz
yae-4353451af2a6edeeca75f5a87186d40d5e81159a.zip
refactor(commands): move flags to commands package
-rw-r--r--internal/commands/add.go42
-rw-r--r--internal/commands/update.go21
-rw-r--r--yae.go63
3 files changed, 67 insertions, 59 deletions
diff --git a/internal/commands/add.go b/internal/commands/add.go
index 4ee15ec..e32d07d 100644
--- a/internal/commands/add.go
+++ b/internal/commands/add.go
@@ -8,6 +8,48 @@ import (
"github.com/urfave/cli/v2"
)
+func AddFlags() []cli.Flag {
+ return []cli.Flag{
+ &cli.BoolFlag{
+ Name: "unpack",
+ Usage: "Unpack the source into the Nix Store",
+ Value: true,
+ },
+ &cli.StringFlag{
+ Name: "type",
+ Usage: "Source type",
+ Required: true,
+ Action: func(c *cli.Context, value string) error {
+ if value != "binary" && value != "git" {
+ return fmt.Errorf("invalid source type: must be 'binary' or 'git'")
+ }
+
+ return nil
+ },
+ },
+ &cli.StringFlag{
+ Name: "version",
+ Usage: "Source version used in identifying latest git source",
+ },
+ &cli.StringFlag{
+ Name: "tag-predicate",
+ Usage: "Git tag predicate used in identifying latest git source",
+ },
+ &cli.StringFlag{
+ Name: "trim-tag-prefix",
+ Usage: "A prefix to trim from remote git tags",
+ },
+ &cli.BoolFlag{
+ Name: "pin",
+ Usage: "Prevent the source from being updated",
+ },
+ &cli.BoolFlag{
+ Name: "force",
+ Usage: "Always force update the source, regardless of unchanged remote tag",
+ },
+ }
+}
+
func Add(sources *yae.Sources) func(c *cli.Context) error {
return func(c *cli.Context) error {
if c.Args().Len() != 2 {
diff --git a/internal/commands/update.go b/internal/commands/update.go
index 66ccfb3..b1ce17b 100644
--- a/internal/commands/update.go
+++ b/internal/commands/update.go
@@ -7,6 +7,27 @@ import (
"github.com/urfave/cli/v2"
)
+func UpdateFlags() []cli.Flag {
+ return []cli.Flag{
+ &cli.BoolFlag{
+ Name: "output-updated-list",
+ Usage: "Output a newline-seperated list of updated sources, regardless of silent mode",
+ },
+ &cli.BoolFlag{
+ Name: "output-formatted-updated-list",
+ Usage: "Output a comma and/or ampersand list of updated sources, regardless of silent mode",
+ },
+ &cli.BoolFlag{
+ Name: "force-hashed",
+ Usage: "Force updates for non-pinned sources that have an unchanged version (recalculate hash)",
+ },
+ &cli.BoolFlag{
+ Name: "force-pinned",
+ Usage: "Force updates for all sources, including pinned sources (can be used with --force-hashed)",
+ },
+ }
+}
+
func Update(sources *yae.Sources) func(c *cli.Context) error {
return func(c *cli.Context) error {
updates := []string{}
diff --git a/yae.go b/yae.go
index 60be017..f5880e2 100644
--- a/yae.go
+++ b/yae.go
@@ -75,46 +75,8 @@ func main() {
Args: true,
ArgsUsage: "<name> <url>",
Usage: "Add a source",
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "unpack",
- Usage: "Unpack the source into the Nix Store",
- Value: true,
- },
- &cli.StringFlag{
- Name: "type",
- Usage: "Source type",
- Required: true,
- Action: func(c *cli.Context, value string) error {
- if value != "binary" && value != "git" {
- return fmt.Errorf("invalid source type: must be 'binary' or 'git'")
- }
-
- return nil
- },
- },
- &cli.StringFlag{
- Name: "version",
- Usage: "Source version used in identifying latest git source",
- },
- &cli.StringFlag{
- Name: "tag-predicate",
- Usage: "Git tag predicate used in identifying latest git source",
- },
- &cli.StringFlag{
- Name: "trim-tag-prefix",
- Usage: "A prefix to trim from remote git tags",
- },
- &cli.BoolFlag{
- Name: "pin",
- Usage: "Prevent the source from being updated",
- },
- &cli.BoolFlag{
- Name: "force",
- Usage: "Always force update the source, regardless of unchanged remote tag",
- },
- },
- Action: commands.Add(&sources),
+ Flags: commands.AddFlags(),
+ Action: commands.Add(&sources),
},
{
Name: "drop",
@@ -127,25 +89,8 @@ func main() {
Args: true,
Usage: "Update one or all sources",
ArgsUsage: "[name]",
- Flags: []cli.Flag{
- &cli.BoolFlag{
- Name: "output-updated-list",
- Usage: "Output a newline-seperated list of updated sources, regardless of silent mode",
- },
- &cli.BoolFlag{
- Name: "output-formatted-updated-list",
- Usage: "Output a comma and/or ampersand list of updated sources, regardless of silent mode",
- },
- &cli.BoolFlag{
- Name: "force-hashed",
- Usage: "Force updates for non-pinned sources that have an unchanged version (recalculate hash)",
- },
- &cli.BoolFlag{
- Name: "force-pinned",
- Usage: "Force updates for all sources, including pinned sources (can be used with --force-hashed)",
- },
- },
- Action: commands.Update(&sources),
+ Flags: commands.UpdateFlags(),
+ Action: commands.Update(&sources),
},
},
}).Run(os.Args); err != nil {