⛩️ Powerful yet Minimal Nix Dependency Manager
flake flakes home-manager nixos go nix dependency dependencies
at main 116 lines 2.5 kB view raw
1package main 2 3import ( 4 "fmt" 5 "os" 6 "time" 7 8 "github.com/Fuwn/yae/internal/commands" 9 "github.com/Fuwn/yae/internal/yae" 10 "github.com/charmbracelet/log" 11 "github.com/urfave/cli/v2" 12) 13 14var Version string 15 16func main() { 17 sources := yae.Environment{} 18 19 if err := (&cli.App{ 20 Name: "yae", 21 Version: Version, 22 Usage: "Nix Dependency Manager", 23 Description: "Nix Dependency Manager", 24 EnableBashCompletion: true, 25 Authors: []*cli.Author{ 26 { 27 Name: "Fuwn", 28 Email: "contact@fuwn.me", 29 }, 30 }, 31 Before: func(c *cli.Context) error { 32 if args := c.Args(); args.Len() == 1 && args.Get(0) == "init" { 33 return nil 34 } 35 36 location := c.String("sources") 37 38 if _, err := os.Stat(location); os.IsNotExist(err) { 39 return fmt.Errorf( 40 "file `%s` was not present, run `yae init` to create it", 41 location, 42 ) 43 } 44 45 return sources.Load(location) 46 }, 47 Flags: []cli.Flag{ 48 &cli.StringFlag{ 49 Name: "sources", 50 Value: "./yae.json", 51 Usage: "Sources path", 52 }, 53 &cli.BoolFlag{ 54 Name: "debug", 55 Usage: "Enable debug output", 56 Action: func(*cli.Context, bool) error { 57 log.SetLevel(log.DebugLevel) 58 59 return nil 60 }, 61 }, 62 &cli.BoolFlag{ 63 Name: "silent", 64 Usage: "Silence log output", 65 Action: func(*cli.Context, bool) error { 66 log.SetLevel(log.WarnLevel) 67 68 return nil 69 }, 70 }, 71 &cli.BoolFlag{ 72 Name: "dry-run", 73 Usage: "Prevents writing to disk", 74 }, 75 }, 76 Copyright: fmt.Sprintf("Copyright (c) 2024-%s Fuwn", fmt.Sprint(time.Now().Year())), 77 ExitErrHandler: func(c *cli.Context, err error) { 78 if err != nil { 79 log.Fatal(err.Error()) 80 } 81 }, 82 Suggest: true, 83 Commands: []*cli.Command{ 84 { 85 Name: "init", 86 Usage: "Initialise a new Yae environment", 87 Action: commands.Init(&sources), 88 }, 89 { 90 Name: "add", 91 Args: true, 92 ArgsUsage: "<name> <url>", 93 Usage: "Add a source", 94 Flags: commands.AddFlags(), 95 Action: commands.Add(&sources), 96 }, 97 { 98 Name: "drop", 99 ArgsUsage: "<name>", 100 Args: true, 101 Usage: "Drop a source", 102 Action: commands.Drop(&sources), 103 }, 104 { 105 Name: "update", 106 Args: true, 107 Usage: "Update one or all sources", 108 ArgsUsage: "[name]", 109 Flags: commands.UpdateFlags(), 110 Action: commands.Update(&sources), 111 }, 112 }, 113 }).Run(os.Args); err != nil { 114 log.Fatal(err.Error()) 115 } 116}