Skip to content

Commit

Permalink
Add info flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo-Hafsaoui committed Dec 21, 2024
1 parent 9fb72da commit 63ebc7f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 32 deletions.
70 changes: 38 additions & 32 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -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")

Check failure on line 14 in cmd/root.go

View workflow job for this annotation

GitHub Actions / Run Linter

ineffectual assignment to err (ineffassign)
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)
}
}
6 changes: 6 additions & 0 deletions internal/adapters/input/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

11 changes: 11 additions & 0 deletions internal/core/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 63ebc7f

Please sign in to comment.