perf: use viper as source for format

This commit is contained in:
Antoine Aflalo
2024-08-27 15:32:05 -04:00
parent 85cefbe8b3
commit 7d824d2aa3
2 changed files with 16 additions and 6 deletions

View File

@@ -54,16 +54,14 @@ func WatchCommand(cmd *cobra.Command, args []string) error {
return fmt.Errorf("the path needs to be a folder") return fmt.Errorf("the path needs to be a folder")
} }
quality, err := cmd.Flags().GetUint8("quality") quality := uint8(viper.GetUint16("quality"))
if err != nil { if quality <= 0 {
return fmt.Errorf("invalid quality value") return fmt.Errorf("invalid quality value")
} }
override, err := cmd.Flags().GetBool("override") override := viper.GetBool("override")
if err != nil {
return fmt.Errorf("invalid quality value")
}
converterType := constant.FindConversionFormat(viper.GetString("format"))
chapterConverter, err := converter.Get(converterType) chapterConverter, err := converter.Get(converterType)
if err != nil { if err != nil {
return fmt.Errorf("failed to get chapterConverter: %v", err) return fmt.Errorf("failed to get chapterConverter: %v", err)
@@ -73,6 +71,7 @@ func WatchCommand(cmd *cobra.Command, args []string) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to prepare converter: %v", err) return fmt.Errorf("failed to prepare converter: %v", err)
} }
log.Printf("Watching [%s] with [override: %t, quality: %d, format: %s]", path, override, quality, converterType.String())
events := make(chan inotifywaitgo.FileEvent) events := make(chan inotifywaitgo.FileEvent)
errors := make(chan error) errors := make(chan error)

View File

@@ -29,3 +29,14 @@ func ListAll() []string {
} }
return formats return formats
} }
func FindConversionFormat(format string) ConversionFormat {
for convFormat, names := range CommandValue {
for _, name := range names {
if name == format {
return convFormat
}
}
}
return DefaultConversion
}