From 771b334dd209360abd80256787c03427fe9a27b8 Mon Sep 17 00:00:00 2001 From: tonitajger Date: Fri, 20 Dec 2024 21:45:05 +0100 Subject: [PATCH] Bugfix for configure command caused by year and day defined as int but attempting to parse as strings in saveIfChanged --- cmd/configure.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cmd/configure.go b/cmd/configure.go index 3a548d2..e7e64ab 100644 --- a/cmd/configure.go +++ b/cmd/configure.go @@ -111,36 +111,26 @@ var configureCmd = &cobra.Command{ }, } -func parseInt(value string) int { - var err error - intValue := 0 - if value != "" { - intValue, err = strconv.Atoi(value) - helpers.HandleErr(err) - } - - return intValue -} func init() { rootCmd.AddCommand(configureCmd) - viper.SetDefault("year", time.Now().Local().Year()) - viper.SetDefault("day", time.Now().Local().Day()) + viper.SetDefault("year", fmt.Sprintf("%d", time.Now().Local().Year())) + viper.SetDefault("day", fmt.Sprintf("%02d", time.Now().Local().Day())) // Ensure it's formatted as a string sessionToken := viper.GetString("session-token") rootDir := viper.GetString("root-dir") pythonExecutable := viper.GetString("python-exec") leaderboard := viper.GetString("leaderboard") - year := parseInt(viper.GetString("year")) - day := parseInt(viper.GetString("day")) + year := viper.GetString("year") + day := viper.GetString("day") - configureCmd.Flags().IntP("year", "y", year, "Selected year") - configureCmd.Flags().Int("day", day, "Selected day") + configureCmd.Flags().StringP("year", "y", year, "Selected year") + configureCmd.Flags().String("day", day, "Selected day") configureCmd.Flags().StringP("session-token", "t", sessionToken, "Session token copied from AOC") configureCmd.Flags().StringP("root-dir", "r", rootDir, "Root directory for the problems") configureCmd.Flags().StringP("python-exec", "p", pythonExecutable, "Path to the python executable") configureCmd.Flags().BoolP("refresh-day", "u", false, "Simply refresh the day") configureCmd.Flags().StringP("leaderboard", "l", leaderboard, "Private leaderboard id") -} +} \ No newline at end of file