From 866fc6bde9acdc0ae30edfac1fd05bdc7b60be77 Mon Sep 17 00:00:00 2001 From: Banana Date: Wed, 19 Jun 2024 14:55:55 +0200 Subject: [PATCH] init the config and init of the read command --- client/go-cli/scientia/cmd/config_init.go | 57 +++++++++++++++++++---- client/go-cli/scientia/cmd/root.go | 3 +- client/go-cli/scientia/go.mod | 5 +- client/go-cli/scientia/go.sum | 3 ++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/client/go-cli/scientia/cmd/config_init.go b/client/go-cli/scientia/cmd/config_init.go index 5fef19a..d37ad6c 100644 --- a/client/go-cli/scientia/cmd/config_init.go +++ b/client/go-cli/scientia/cmd/config_init.go @@ -7,23 +7,46 @@ import ( "github.com/kirsle/configdir" "github.com/spf13/cobra" - Helper "scientia/lib" ) -var configInitCmd = &cobra.Command { - Use: "init", - Short: "Initialize config", - Long: `Read, edit and initialize scientia configuration`, - Run: func(cmd *cobra.Command, args []string) { - initConfig() - }, -} +/** + * scientia + * + * Copyright 2023 - 2024 Johannes Keßler + * + * https://www.bananas-playground.net/projekt/scientia/ + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE + * + * You should have received a copy of the + * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + * along with this program. If not, see http://www.sun.com/cddl/cddl.html + */ func init() { configCmd.AddCommand(configInitCmd) + configCmd.AddCommand(configReadCmd) +} + +// The Config file struct +type Config struct { + Endpoint struct { + Host string `yaml:"host"` + Secret string `yaml:"secret"` + } `yaml:"endpoint"` } +var configInitCmd = &cobra.Command{ + Use: "init", + Short: "Initialize config", + Long: `Read, edit and initialize scientia configuration`, + Run: func(cmd *cobra.Command, args []string) { + initConfig() + }, +} func initConfig() { configPath := configdir.LocalConfig("scientia") @@ -43,6 +66,7 @@ func initConfig() { Helper.ErrorCheck(err, "Can not create config file!") defer newConfig.Close() + // yaml package can not write comments yet, so creating it manually _, err = fmt.Fprintf(newConfig, "# scientia go client config file.\n") Helper.ErrorCheck(err, "Can not write to new config file") fmt.Fprintf(newConfig, "# See %s for more details.\n", Helper.Website) @@ -53,6 +77,19 @@ func initConfig() { } else { fmt.Printf("Config file exists.: %s \n", configFile) - fmt.Println("User read to display or edit to modify the config file.") + fmt.Println("Use 'read' to display or 'edit' to modify the config file.") } } + +var configReadCmd = &cobra.Command{ + Use: "read", + Short: "Read config file", + Long: "Read the config file and print it to stdout", + Run: func(cmd *cobra.Command, args []string) { + readConfig() + }, +} + +func readConfig() { + +} diff --git a/client/go-cli/scientia/cmd/root.go b/client/go-cli/scientia/cmd/root.go index e9a0d79..d20eeaa 100644 --- a/client/go-cli/scientia/cmd/root.go +++ b/client/go-cli/scientia/cmd/root.go @@ -14,7 +14,7 @@ var FlagVerbose bool var FlagDebug bool // The rootCmd -var rootCmd = &cobra.Command { +var rootCmd = &cobra.Command{ Use: "scientia", Short: "scientia client", Long: `cognizance, insight, knowledge. @@ -31,6 +31,7 @@ More information: https://www.bananas-playground.net/projekt/scientia/`, } func init() { + rootCmd.CompletionOptions.DisableDefaultCmd = true // add global flags rootCmd.PersistentFlags().BoolVarP(&FlagVerbose, "verbose", "v", false, "verbose output") rootCmd.PersistentFlags().BoolVarP(&FlagDebug, "debug", "d", false, "debug output") diff --git a/client/go-cli/scientia/go.mod b/client/go-cli/scientia/go.mod index b46d0b3..5199bec 100644 --- a/client/go-cli/scientia/go.mod +++ b/client/go-cli/scientia/go.mod @@ -1,10 +1,13 @@ module scientia -go 1.22.4 +go 1.21.10 require ( + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spf13/cobra v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/client/go-cli/scientia/go.sum b/client/go-cli/scientia/go.sum index 8d8834d..4dc7dd4 100644 --- a/client/go-cli/scientia/go.sum +++ b/client/go-cli/scientia/go.sum @@ -1,12 +1,15 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNqOcFIbuqFjAWPVtP688j5QMgmo6OHU= github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -- 2.39.5