-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnix-hive.go
71 lines (60 loc) · 1.29 KB
/
nix-hive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/spf13/cobra"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
var err error
tmp, err = os.MkdirTemp(``, `hive-`)
if err != nil {
panic(err)
}
defer func() {
err := os.RemoveAll(tmp)
if err != nil {
panic(err)
}
}()
err = rootCmd.ExecuteContext(ctx)
if err != nil {
os.Exit(1)
}
}
var rootCmd = &cobra.Command{
Use: `nix-hive`,
Short: `A system for managing identical NixOS systems`,
Long: `Nix-Hive is a tool that builds NixOS systems and deploys them efficiently.`,
PersistentPreRunE: preRun,
PersistentPostRunE: postRun,
SilenceUsage: true,
}
func preRun(cmd *cobra.Command, args []string) error {
err := loadInventory(cmd, args)
if err != nil {
return err
}
err = applyState()
if err != nil {
return err
}
return nil
}
func postRun(cmd *cobra.Command, args []string) error {
err := saveState()
if err != nil {
return err
}
return nil
}
var tmp = ``
func inform(ctx context.Context, msg string, info ...interface{}) {
fmt.Fprintf(os.Stderr, ".. "+msg+"\n", info...)
}
func warn(ctx context.Context, msg string, info ...interface{}) {
fmt.Fprintf(os.Stderr, ":: "+msg+"\n", info...)
}