Переглянути джерело

starting fresh with the go client

Signed-off-by: Banana <mail@bananas-playground.net>
Banana 3 місяців тому
батько
коміт
089338c1aa

+ 1 - 1
CHANGELOG

@@ -1,5 +1,5 @@
 1.x Atlas -
-	+ i18n. See upgrade-from-1.0.txt for more details.
+	+ i18n. See upgrade-from-1.0.md for more details.
 	+ PHP 8.1 stuff
 	+ Search
 	+ Updated clients. A cli client written in Go.

+ 11 - 0
client/go-cli/scientia/Makefile

@@ -0,0 +1,11 @@
+all: scientia
+
+scientia:
+	@echo "Building for local os/arch..."
+	go build -o scientia
+	chmod u+x scientia
+
+devbuild: clean scientia
+
+clean:
+	rm -f scientia

+ 23 - 0
client/go-cli/scientia/cmd/config.go

@@ -0,0 +1,23 @@
+package cmd
+
+import (
+	"os"
+
+	"github.com/spf13/cobra"
+)
+
+var configCmd = &cobra.Command {
+	Use: "config",
+	Short: "Modify config",
+	Long: "Read, edit and initialize scientia configuration.",
+	Run: func(cmd *cobra.Command, args []string) {
+		if len(args) == 0 {
+			cmd.Help()
+			os.Exit(0)
+		}
+	},
+}
+
+func init() {
+	rootCmd.AddCommand(configCmd)
+}

+ 58 - 0
client/go-cli/scientia/cmd/config_init.go

@@ -0,0 +1,58 @@
+package cmd
+
+import (
+	"errors"
+	"fmt"
+	"os"
+
+	"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()
+	},
+}
+
+func init() {
+	configCmd.AddCommand(configInitCmd)
+}
+
+
+func initConfig() {
+	configPath := configdir.LocalConfig("scientia")
+	err := configdir.MakePath(configPath) // Ensure it exists.
+	Helper.ErrorCheck(err, "No $HOME/.config/scientia directory available?")
+	var configFile = configPath + "/.scientia.yaml"
+
+	if FlagDebug {
+		fmt.Printf("Local user config path: %s\n", configPath)
+		fmt.Printf("Local user config file: %s\n", configFile)
+	}
+
+	if _, err := os.Stat(configFile); errors.Is(err, os.ErrNotExist) {
+		fmt.Printf("Creating new default config file: %s \n", configFile)
+
+		newConfig, err := os.Create(configFile)
+		Helper.ErrorCheck(err, "Can not create config file!")
+		defer newConfig.Close()
+
+		_, 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)
+		fmt.Fprintf(newConfig, "# Version: %s\n", Helper.Version)
+		fmt.Fprintf(newConfig, "endpoint:\n")
+		fmt.Fprintf(newConfig, "  host: http://your-scientia-endpoi.nt/api.php\n")
+		fmt.Fprintf(newConfig, "  secret: %s\n", Helper.RandStringBytes(50))
+
+	} else {
+		fmt.Printf("Config file exists.: %s \n", configFile)
+		fmt.Println("User read to display or edit to modify the config file.")
+	}
+}

+ 44 - 0
client/go-cli/scientia/cmd/root.go

@@ -0,0 +1,44 @@
+package cmd
+
+import (
+	"fmt"
+	"os"
+
+	"github.com/spf13/cobra"
+)
+
+// FlagVerbose is a global flag
+var FlagVerbose bool
+
+// FlagDebug is a global flag
+var FlagDebug bool
+
+// The rootCmd
+var rootCmd = &cobra.Command {
+	Use:   "scientia",
+	Short: "scientia client",
+	Long: `cognizance, insight, knowledge.
+A client to scientia.
+More information: https://www.bananas-playground.net/projekt/scientia/`,
+	Run: func(cmd *cobra.Command, args []string) {
+
+		// display help if no arguments are given
+		if len(args) == 0 {
+			cmd.Help()
+			os.Exit(0)
+		}
+	},
+}
+
+func init() {
+	// add global flags
+	rootCmd.PersistentFlags().BoolVarP(&FlagVerbose, "verbose", "v", false, "verbose output")
+	rootCmd.PersistentFlags().BoolVarP(&FlagDebug, "debug", "d", false, "debug output")
+}
+
+func Execute() {
+	if err := rootCmd.Execute(); err != nil {
+		fmt.Fprintln(os.Stderr, err)
+		os.Exit(1)
+	}
+}

+ 10 - 0
client/go-cli/scientia/go.mod

@@ -0,0 +1,10 @@
+module scientia
+
+go 1.22.4
+
+require (
+	github.com/inconshreveable/mousetrap v1.1.0 // indirect
+	github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f // indirect
+	github.com/spf13/cobra v1.8.1 // indirect
+	github.com/spf13/pflag v1.0.5 // indirect
+)

+ 12 - 0
client/go-cli/scientia/go.sum

@@ -0,0 +1,12 @@
+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/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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 26 - 0
client/go-cli/scientia/lib/helpers.go

@@ -0,0 +1,26 @@
+package lib
+
+import (
+	"log"
+	"math/rand"
+)
+
+const Version string = "1.0"
+const Website string = "https://www.bananas-playground.net/projekt/scientia/"
+
+// ErrorCheck if error then display it with an addition message
+func ErrorCheck(e error, msg string) {
+	if e != nil {
+		log.Fatal(msg, " ; Message: ", e)
+	}
+}
+
+// RandStringBytes creates just a random string
+func RandStringBytes(n int) string {
+	var letters = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
+	b := make([]byte, n)
+	for i := range b {
+		b[i] = letters[rand.Intn(len(letters))]
+	}
+	return string(b)
+}

+ 9 - 0
client/go-cli/scientia/main.go

@@ -0,0 +1,9 @@
+package main
+
+import (
+	"scientia/cmd"
+)
+
+func main() {
+	cmd.Execute()
+}

BIN
client/go-cli/scientia/scientia


+ 0 - 0
client/go-cli/Makefile → client/go-cli_/Makefile


+ 0 - 0
client/go-cli/README.md → client/go-cli_/README.md


+ 0 - 0
client/go-cli/go.mod → client/go-cli_/go.mod


+ 0 - 0
client/go-cli/go.sum → client/go-cli_/go.sum


+ 1 - 1
client/go-cli/scientia-cli.go → client/go-cli_/scientia-cli.go

@@ -18,7 +18,7 @@ import (
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *