@@ -11,6 +11,10 @@ import (
1111 "github.com/urfave/cli/v2"
1212)
1313
14+ var (
15+ maxDBBytes = 1946
16+ )
17+
1418func main () {
1519 log .SetFlags (0 )
1620
@@ -23,7 +27,7 @@ func main() {
2327 Aliases : []string {"i" },
2428 Usage : "initializes a new database" ,
2529 Action : func (cCtx * cli.Context ) error {
26- database := setupDB (cCtx . String ( "db" ) )
30+ database := setupDB (cCtx )
2731 database .Init ()
2832 return nil
2933 },
@@ -33,7 +37,7 @@ func main() {
3337 Aliases : []string {"s" },
3438 Usage : "sets a key" ,
3539 Action : func (cCtx * cli.Context ) error {
36- database := setupDB (cCtx . String ( "db" ) )
40+ database := setupDB (cCtx )
3741
3842 key := cCtx .Args ().First ()
3943 val := cCtx .Args ().Get (1 )
@@ -51,7 +55,7 @@ func main() {
5155 Aliases : []string {"g" },
5256 Usage : "get a value from given key" ,
5357 Action : func (cCtx * cli.Context ) error {
54- database := setupDB (cCtx . String ( "db" ) )
58+ database := setupDB (cCtx )
5559 fmt .Println (database .Get (cCtx .Args ().First ()))
5660 return nil
5761 },
@@ -61,7 +65,7 @@ func main() {
6165 Aliases : []string {"l" },
6266 Usage : "list all keys" ,
6367 Action : func (cCtx * cli.Context ) error {
64- database := setupDB (cCtx . String ( "db" ) )
68+ database := setupDB (cCtx )
6569 keys := database .List ()
6670 fmt .Println (strings .Join (keys , "\n " ))
6771 return nil
@@ -74,6 +78,11 @@ func main() {
7478 Value : "0" ,
7579 Usage : "database to use" ,
7680 },
81+ & cli.BoolFlag {
82+ Name : "no-info" ,
83+ Value : false ,
84+ Usage : "Do not print db usage information" ,
85+ },
7786 },
7887 }
7988
@@ -83,12 +92,15 @@ func main() {
8392
8493}
8594
86- func setupDB (name string ) Database {
95+ func setupDB (ctx * cli. Context ) Database {
8796 token := os .Getenv ("HCLOUD_TOKEN" )
97+ name := ctx .String ("db" )
98+ noInfo := ctx .Bool ("no-info" )
8899
89100 return Database {
90101 Client : hcloud .NewClient (hcloud .WithToken (token )),
91102 Context : context .Background (),
92103 Name : fmt .Sprintf ("hkv-%s" , name ),
104+ NoInfo : noInfo ,
93105 }
94106}
0 commit comments