I'm currently working on a CLI project using Go and cobra. I've completed the code and now I built the project and trying to run .However, I'm encountering an error that I can't seem to resolve. The error message I'm getting is:
Error: unknown shorthand flag: 'o' in -o
I'm not sure what's causing this error and I'm not sure how to proceed.
Here's the main func:
func main() {
var rootCmd = &cobra.Command{
Use: "Convertica",
Short: "Convertica is a file format converter",
}
var convCmd = &cobra.Command{
Use: "convert",
Short: "Convert file format",
Run: func(cmd *cobra.Command, args []string) {
converter(cmd, args)
},
}
var outCmd = &cobra.Command{
Use: "outDir",
Short: "The directory of the converted file",
Run: func(cmd *cobra.Command, args []string) {
content, _ := readContent(cmd, args)
newName := converter(cmd, args)
saveContentToDirectory(cmd, content, newName)
},
}
var formatCmd = &cobra.Command{
Use: "format",
Short: "Format of the new file",
Run: func(cmd *cobra.Command, args []string) {
converter(cmd, args)
},
}
convCmd.Flags().StringP("file", "c", "", "The directory of the file to be compressed")
outCmd.Flags().StringP("dir", "o", "", "The directory of the converted file")
formatCmd.Flags().StringP("format", "f", "", "Format of the new file")
rootCmd.AddCommand(convCmd)
rootCmd.AddCommand(outCmd)
rootCmd.AddCommand(formatCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}