Skip to content

Commit

Permalink
Add file completion for output flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclmr committed Aug 10, 2023
1 parent 11f062b commit 5534d3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions cmd/icm/download_owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newDownloadOwnersCmd(
timestampUpdater data.TimestampUpdater,
ownersDownloader http.OwnersDownloader,
ownerCSVPath string,
) *cobra.Command {
) (*cobra.Command, error) {
filePath := filePathValue{value: ownerCSVPath}

downloadOwnersCmd := &cobra.Command{
Expand All @@ -58,14 +58,20 @@ icm download-owners
# Use semicolon as a separator. For using double quotes please see existing
# owner.csv file.
echo 'AAA;my company;my city;my country' >> $HOME/.icm/data/custom-owner.csv`,
Args: cobra.NoArgs,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
return overwriteOwnersFile(writeOwnersCSVFunc, timestampUpdater, ownersDownloader, filePath.value)
},
}
downloadOwnersCmd.Flags().VarP(&filePath, "output", "o", "output file")

return downloadOwnersCmd
err := downloadOwnersCmd.MarkFlagFilename("output")
if err != nil {
return nil, err
}

return downloadOwnersCmd, nil
}

func overwriteOwnersFile(writeOwnersCSV data.WriteOwnersCSVFunc, timestampUpdater data.TimestampUpdater, ownersDownloader http.OwnersDownloader, filePath string) error {
Expand Down
6 changes: 5 additions & 1 deletion cmd/icm/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ Visit github.com/meyermarcel/icm for more docs, issues, pull requests and feedba
return nil, err
}
rootCmd.AddCommand(cmd)
rootCmd.AddCommand(newDownloadOwnersCmd(ownerCreator, timestampUpdater, ownersDownloader, ownerCSVPath))
downloadOwnersCmd, err := newDownloadOwnersCmd(ownerCreator, timestampUpdater, ownersDownloader, ownerCSVPath)
if err != nil {
return nil, err
}
rootCmd.AddCommand(downloadOwnersCmd)
rootCmd.AddCommand(newDocCmd(rootCmd))

return rootCmd, nil
Expand Down

0 comments on commit 5534d3f

Please sign in to comment.