From 63ebc7fa5d2d94c6f0410b4726c73856aa850ae2 Mon Sep 17 00:00:00 2001 From: Theo-Hafsaoui Date: Sat, 21 Dec 2024 17:00:09 +0100 Subject: [PATCH] Add info flag --- cmd/root.go | 70 ++++++++++++++++++---------------- internal/adapters/input/cli.go | 6 +++ internal/core/generate.go | 11 ++++++ 3 files changed, 55 insertions(+), 32 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 69cb3e6..7687b6c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,42 +1,48 @@ package cmd import ( - "anemon/internal/adapters/input" - "github.com/spf13/cobra" - "os" + "anemon/internal/adapters/input" + "github.com/spf13/cobra" + "os" ) var rootCmd = &cobra.Command{ - Use: "anemon", - Short: "A CV generator", - Long: `This CLI tool, automates the generation of customized CVs from Markdown files based on a specified configuration.`, - RunE: func(cmd *cobra.Command, args []string) error { - threshold, err := cmd.Flags().GetInt("threshold") - if err != nil { - return err - } - input.ChangeOverflowThreshold(threshold) - - generate, err := cmd.Flags().GetBool("generate") - if err != nil { - return err - } - if generate { - root, err := os.Getwd() - if err != nil { - return err - } - return input.GenerateCVFromMarkDownToLatex(root) - } - - return nil - }, + Use: "anemon", + Short: "A CV generator", + Long: `This CLI tool, automates the generation of customized CVs from Markdown files based on a specified configuration.`, + RunE: func(cmd *cobra.Command, args []string) error { + threshold, err := cmd.Flags().GetInt("threshold") + root, err := os.Getwd() + if err != nil { return err } + + if err != nil { + return err + } + input.ChangeOverflowThreshold(threshold) + + generate, err := cmd.Flags().GetBool("generate") + if err != nil { return err } + + if generate { + return input.GenerateCVFromMarkDownToLatex(root) + } + + info, err := cmd.Flags().GetBool("cvInfo") + if err != nil { return err } + if info{ + input.PrintAllCvs(root) + return nil + } + + return nil + }, } func Execute() { - rootCmd.Flags().IntP("threshold", "t", 1, "Set the page overflow threshold (default 1)") - rootCmd.Flags().BoolP("generate", "g", false, "Generate a CV") - if err := rootCmd.Execute(); err != nil { - os.Exit(1) - } + rootCmd.Flags().IntP("threshold", "t", 1, "Set the page overflow threshold (default 1)") + rootCmd.Flags().BoolP("generate", "g", false, "Generate a CV") + rootCmd.Flags().BoolP("cvInfo", "i", false, "Get all the info of all the cvs") + if err := rootCmd.Execute(); err != nil { + os.Exit(1) + } } diff --git a/internal/adapters/input/cli.go b/internal/adapters/input/cli.go index 36e0d4b..11475e3 100644 --- a/internal/adapters/input/cli.go +++ b/internal/adapters/input/cli.go @@ -22,3 +22,9 @@ func GenerateCVFromMarkDownToLatex(root string) error { func ChangeOverflowThreshold(newThreshold int) { core.SetOverflowThreshold(newThreshold) } +// Print info in the prompt for all the cvs +func PrintAllCvs(root string) { + source := MarkdownSource{} + core.GetInfoAllCvs(root,&source) +} + diff --git a/internal/core/generate.go b/internal/core/generate.go index 6e68617..9fc4261 100644 --- a/internal/core/generate.go +++ b/internal/core/generate.go @@ -237,6 +237,17 @@ func (s *BuilderService) GetService() CVService { } } +//Get all info of the cvs and prompt them in the stdout +func GetInfoAllCvs(root string, source Source){ + cvs, err := source.GetCVsFrom(root) + if err != nil{ + slog.Warn(err.Error()) + } + for _,cv := range cvs{ + cv.Print() + } +} + // Set the threshold value dynamically func SetOverflowThreshold(newThreshold int) { TresholdPageOverFlow.mutex.Lock()