diff --git a/cmd/list.go b/cmd/list.go index 67e9518..ede9432 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -7,14 +7,14 @@ import ( "github.com/spf13/cobra" ) -// sheetsCmd represents the sheets command +// listSheetsCmd represents the list command. var listSheetsCmd = &cobra.Command{ Use: "list", Short: "List the sheets of the xlsx file", Long: `List the sheets of the xlsx file.`, RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { - return fmt.Errorf("Please specify the xlsx file.") + return fmt.Errorf("please specify the xlsx file") } list, err := xlsxsql.XLSXSheet(args[0]) if err != nil { diff --git a/cmd/query.go b/cmd/query.go index c56344f..e2cce1d 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -87,7 +87,7 @@ func stdWriter(fileName string) (trdsql.Writer, error) { return w, nil } -// queryCmd represents the query command +// queryCmd represents the query command. var queryCmd = &cobra.Command{ Use: "query", Short: "Executes the specified SQL query against the xlsx file", diff --git a/cmd/root.go b/cmd/root.go index 552c930..ceb6c77 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,12 +3,13 @@ package cmd import ( "fmt" "os" + "strings" _ "github.com/noborus/xlsxsql" "github.com/spf13/cobra" ) -// rootCmd represents the base command when called without any subcommands +// rootCmd represents the base command when called without any subcommands. var rootCmd = &cobra.Command{ Use: "xlsxsql", Short: "Execute SQL against xlsx file.", @@ -28,7 +29,7 @@ Output to CSV and various formats.`, } var ( - // Version represents the version + // Version represents the version. Version string // Revision set "git rev-parse --short HEAD" Revision string @@ -82,9 +83,14 @@ func init() { // Input rootCmd.PersistentFlags().IntVarP(&Skip, "skip", "s", 0, "Skip the number of lines") rootCmd.PersistentFlags().BoolVarP(&Header, "header", "H", false, "Input header") - // Output - rootCmd.PersistentFlags().StringVarP(&OutFormat, "out", "o", "GUESS", "Output Format[CSV|AT|LTSV|JSON|JSONL|TBLN|RAW|MD|VF|YAML|XLSX]") + validOutFormats := []string{"CSV", "AT", "LTSV", "JSON", "JSONL", "TBLN", "RAW", "MD", "VF", "YAML", "XLSX"} + outputFormats := fmt.Sprintf("Output Format[%s]", strings.Join(validOutFormats, "|")) + rootCmd.PersistentFlags().StringVarP(&OutFormat, "out", "o", "GUESS", outputFormats) + // Register the completion function for the --out flag + _ = rootCmd.RegisterFlagCompletionFunc("out", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return validOutFormats, cobra.ShellCompDirectiveDefault + }) rootCmd.PersistentFlags().StringVarP(&OutFileName, "out-file", "O", "", "File name to output to file") rootCmd.PersistentFlags().BoolVarP(&OutHeader, "out-header", "", false, "Output header") rootCmd.PersistentFlags().StringVarP(&OutSheetName, "out-sheet", "", "", "Sheet name to output to xlsx file") diff --git a/cmd/table.go b/cmd/table.go index ab48b30..d6d578e 100644 --- a/cmd/table.go +++ b/cmd/table.go @@ -6,14 +6,14 @@ import ( "github.com/spf13/cobra" ) -// tableCmd represents the table command +// tableCmd represents the table command. var tableCmd = &cobra.Command{ Use: "table", Short: "SQL(SELECT * FROM table) for xlsx", Long: `Execute SELECT * FROM table, assuming the xlsx file as a table.`, RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { - return fmt.Errorf("Please specify the xlsx file.") + return fmt.Errorf("please specify the xlsx file") } query := "SELECT * FROM " + args[0] return exec([]string{query}) diff --git a/go.mod b/go.mod index b0acb45..56ee0c8 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/xuri/efp v0.0.0-20241211021726-c4e992084aa6 // indirect github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect + golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect golang.org/x/net v0.32.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/term v0.27.0 // indirect diff --git a/go.sum b/go.sum index e263c23..35cb772 100644 --- a/go.sum +++ b/go.sum @@ -96,8 +96,8 @@ github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9 golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/exp v0.0.0-20241210194714-1829a127f884 h1:Y/Mj/94zIQQGHVSv1tTtQBDaQaJe62U9bkDZKKyhPCU= -golang.org/x/exp v0.0.0-20241210194714-1829a127f884/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=