|
@@ -3,7 +3,6 @@ package cmd
|
|
import (
|
|
import (
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/kirsle/configdir"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
"os"
|
|
"os"
|
|
Helper "scientia/lib"
|
|
Helper "scientia/lib"
|
|
@@ -25,6 +24,8 @@ import (
|
|
* along with this program. If not, see http://www.sun.com/cddl/cddl.html
|
|
* along with this program. If not, see http://www.sun.com/cddl/cddl.html
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+// Subcommand of config
|
|
|
|
+// to init the config with default values.
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
configCmd.AddCommand(configInitCmd)
|
|
configCmd.AddCommand(configInitCmd)
|
|
@@ -43,12 +44,14 @@ var configInitCmd = &cobra.Command {
|
|
|
|
|
|
// initConfig which creates the default config file
|
|
// initConfig which creates the default config file
|
|
func initConfig() {
|
|
func initConfig() {
|
|
- err := configdir.MakePath(ScientiaConfigPath) // Ensure it exists.
|
|
|
|
- Helper.ErrorCheck(err, "No $HOME/.config/scientia directory available?")
|
|
|
|
|
|
+ if _, err := os.Stat(ScientiaConfigPath); os.IsNotExist(err) {
|
|
|
|
+ err := os.MkdirAll(ScientiaConfigPath, os.ModePerm);
|
|
|
|
+ Helper.ErrorCheck(err, "No $HOME/.config/scientia directory available?")
|
|
|
|
+ }
|
|
|
|
|
|
if FlagDebug {
|
|
if FlagDebug {
|
|
fmt.Printf("DEBUG Local user config path: %s\n", ScientiaConfigPath)
|
|
fmt.Printf("DEBUG Local user config path: %s\n", ScientiaConfigPath)
|
|
- fmt.Printf("DEBUG Local user config file: %s\n", ScientiaConfigPath)
|
|
|
|
|
|
+ fmt.Printf("DEBUG Local user config file: %s\n", ScientiaConfigFile)
|
|
}
|
|
}
|
|
|
|
|
|
if _, err := os.Stat(ScientiaConfigFile); errors.Is(err, os.ErrNotExist) {
|
|
if _, err := os.Stat(ScientiaConfigFile); errors.Is(err, os.ErrNotExist) {
|
|
@@ -64,7 +67,8 @@ func initConfig() {
|
|
fmt.Fprintf(newConfig, "# See %s for more details.\n", Helper.Website)
|
|
fmt.Fprintf(newConfig, "# See %s for more details.\n", Helper.Website)
|
|
fmt.Fprintf(newConfig, "# Version: %s\n", Helper.Version)
|
|
fmt.Fprintf(newConfig, "# Version: %s\n", Helper.Version)
|
|
fmt.Fprintf(newConfig, "endpoint:\n")
|
|
fmt.Fprintf(newConfig, "endpoint:\n")
|
|
- fmt.Fprintf(newConfig, " url: \"http://your-scientia-endpoi.nt/api.php\"\n")
|
|
|
|
|
|
+ fmt.Fprintf(newConfig, " add: \"http://your-scientia-endpoi.nt/add.php\"\n")
|
|
|
|
+ fmt.Fprintf(newConfig, " get: \"http://your-scientia-endpoi.nt/get.php\"\n")
|
|
fmt.Fprintf(newConfig, " secret: \"%s\"\n", Helper.RandStringBytes(50))
|
|
fmt.Fprintf(newConfig, " secret: \"%s\"\n", Helper.RandStringBytes(50))
|
|
|
|
|
|
fmt.Println("Created a new default config file. Please use the edit command to update it with your settings.")
|
|
fmt.Println("Created a new default config file. Please use the edit command to update it with your settings.")
|