Initial commit still with some hardcoded things

This commit is contained in:
2025-09-16 22:57:21 +01:00
commit b578976dad
14 changed files with 722 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
// Package cmd provides a command line interface to interact with this model.
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "invcertsw",
Short: "CLI invcertsw utility",
Long: `Utility to identify invoicing software from invoices`,
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// rootCmd.PersistentFlags().BoolP("dbstore", "s", false, "Store data in database")
}
+30
View File
@@ -0,0 +1,30 @@
package cmd
import (
"log"
api "github.com/ESilva15/PTInvCertSWDB/api"
"github.com/spf13/cobra"
)
func restServer(cmd *cobra.Command, args []string) {
// TODO - We need to load the data somehow to return it
err := api.RunServer()
if err != nil {
log.Fatal("Failed to run HTTP server:", err)
}
}
// shelf
var restServerCMD = &cobra.Command{
Use: "http",
Short: "",
Long: ``,
Args: nil,
Run: restServer,
}
func init() {
rootCmd.AddCommand(restServerCMD)
}
+38
View File
@@ -0,0 +1,38 @@
package cmd
import (
"log"
"os"
scraper "github.com/ESilva15/PTInvCertSWDB/scraper"
"github.com/spf13/cobra"
)
func scrapeAction(cmd *cobra.Command, args []string) {
list := scraper.Scrape()
file, err := os.OpenFile("./swdb.yaml", os.O_CREATE|os.O_RDWR, 0744)
if err != nil {
log.Fatal("Failed to open DB file:", err)
}
n, err := file.Write(list.ToYAML())
if err != nil {
log.Fatal("Error writing data to db file:", err)
}
log.Println("Succesfully wrote ", n, "to db file")
}
// shelf
var scrapeCMD = &cobra.Command{
Use: "scrape",
Short: "",
Long: ``,
Args: nil,
Run: scrapeAction,
}
func init() {
rootCmd.AddCommand(scrapeCMD)
}