140 lines
4.0 KiB
Go
140 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"kode-starter/cmdCreate"
|
|
"kode-starter/cmdEnv"
|
|
"kode-starter/cmdLists"
|
|
"kode-starter/config"
|
|
"kode-starter/utils"
|
|
"kode-starter/version"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "kode-creator.exe",
|
|
Short: "Simple cli app create startup project",
|
|
Long: `A simple CLI app to work with Github, Gitea`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
config.SetInformations(cmd, args)
|
|
mainProgram(cmd, args)
|
|
},
|
|
}
|
|
|
|
var token, org, name, private, description, group string
|
|
var verbose, createFlag bool
|
|
var listFlag, envVariablesFlag, groupFlag bool
|
|
|
|
func init() {
|
|
|
|
rootCmd.Flags().BoolP("help", "h", false, "Show help for create command")
|
|
|
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "mode verbose")
|
|
rootCmd.PersistentFlags().BoolVarP(&createFlag, "json", "j", false, "Print output as json format")
|
|
// rootCmd.PersistentFlags().BoolVarP(&envVariablesFlag, "env", "e", false, "environment variables ")
|
|
|
|
cmdLists.ListCmd.Flags().StringVarP(&token, "token", "t", "", "Github token")
|
|
cmdLists.ListCmd.Flags().StringVarP(&org, "org", "o", "", "Github organization")
|
|
|
|
cmdCreate.CreateCmd.Flags().StringVarP(&token, "token", "t", "", "Github token")
|
|
cmdCreate.CreateCmd.Flags().StringVarP(&org, "org", "o", "", "Github organization")
|
|
cmdCreate.CreateCmd.Flags().StringVarP(&name, "name", "n", "", "Project name")
|
|
cmdCreate.CreateCmd.Flags().StringVarP(&description, "desc", "d", "", "Description")
|
|
cmdCreate.CreateCmd.Flags().StringVarP(&private, "private", "p", "", "true/false")
|
|
|
|
cmdEnv.EnvCmd.Flags().BoolVarP(&listFlag, "list", "l", false, "List options")
|
|
cmdEnv.EnvCmd.Flags().BoolVarP(&envVariablesFlag, "env", "e", false, "environnement variables")
|
|
cmdEnv.EnvCmd.Flags().BoolVarP(&groupFlag, "group", "g", false, "categories of informations")
|
|
cmdEnv.EnvCmd.Flags().StringVarP(&group, "filter", "f", "", "filter for a specific category")
|
|
|
|
rootCmd.AddCommand(cmdLists.ListCmd)
|
|
rootCmd.AddCommand(cmdCreate.CreateCmd)
|
|
rootCmd.AddCommand(cmdEnv.EnvCmd)
|
|
|
|
}
|
|
|
|
func mainProgram(cmd *cobra.Command, args []string) {
|
|
|
|
config.SetInformations(cmd, args)
|
|
|
|
fmt.Println("Header")
|
|
utils.PrintHeader()
|
|
|
|
// Check if the help flag is set
|
|
if cmd.Flags().Changed("help") || cmd.Flags().Changed("h") {
|
|
utils.PrintHelpFormated(version.GetFullVersion(), config.GetAuthor(), config.GetBuildDate(), cmd)
|
|
return
|
|
} else {
|
|
|
|
// If no flag is set, show help
|
|
utils.PrintHelpFormated(version.GetFullVersion(), config.GetAuthor(), config.GetBuildDate(), cmd)
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func main() {
|
|
|
|
filename := "config.yml"
|
|
|
|
cfg, err := config.LoadConfig(filename)
|
|
if err != nil {
|
|
log.Fatalf("error loading config file: %v", err)
|
|
}
|
|
|
|
// list all elements from category "Category-Go"
|
|
ListSoftwares, err := cfg.GetListSoftware("Go")
|
|
if err != nil {
|
|
log.Fatalf("error getting logiciels: %v", err)
|
|
}
|
|
|
|
for _, s := range ListSoftwares {
|
|
fmt.Printf("Software: %s\n", s)
|
|
|
|
Software, err := cfg.GetSoftware("Go", s)
|
|
if err != nil {
|
|
log.Fatalf("error getting logiciel: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Nom: %s\n", Software.Name)
|
|
fmt.Printf("Version: %s\n", Software.Version)
|
|
fmt.Printf("Auteur: %s\n", Software.Author)
|
|
fmt.Printf("Location: %s\n", Software.Location)
|
|
fmt.Printf("Description: %s\n", Software.Description)
|
|
|
|
}
|
|
|
|
EnvironmentVariables, err := cfg.GetListEnvironmentVariables("Go")
|
|
if err != nil {
|
|
log.Fatalf("error getting environment variables: %v", err)
|
|
}
|
|
|
|
for _, e := range EnvironmentVariables {
|
|
fmt.Printf("Environment variable: %s\n", e)
|
|
EnvVar, err := cfg.GetEnvironmentVariables("Go", e)
|
|
if err != nil {
|
|
log.Fatalf("error getting environment variable: %v", err)
|
|
}
|
|
fmt.Printf("%s = %s\n", e, EnvVar)
|
|
}
|
|
|
|
// liste configuration elements for "directory"
|
|
// Dir, err := cfg.GetDirectory("Category-Go", "source")
|
|
// if err != nil {
|
|
// log.Fatalf("error getting directory: %v", err)
|
|
// }
|
|
// for _, d := range Dir.Path {
|
|
// fmt.Printf("Directory: %s\n", d)
|
|
// }
|
|
|
|
os.Exit(0)
|
|
|
|
rootCmd.Execute()
|
|
|
|
}
|