Closed luccamendonca closed 3 years ago
@marcelometal I've made some changes based on the comments you left!
Now, there are still a couple things I think we could improve along the way if we find it's necessary:
Usage
section when RunE
returns an error (we could use cmd.Help()
, but it doesn't seem like a good approach)Anyway, the post-process
command seems fairly usable already :)
Lemme know if there's anything you may want to change ;)
Hi, @luccamendonca
I don't know if is possible to iterate over postProcessSteps
map, create a new command (cobra.Command{}
) and add it as a sub-command, this way:
var politicalPartyCmd = &cobra.Command{}
postProcessCmd.AddCommand(politicalPartyCmd)
Adding a sub-command the output will be:
Usage:
collector post-process [command]
Available Commands:
political-party Post process...
political-office Post process...
candidacy-status Post process...
education Post process...
Sounds good?
I think it should be possible, indeed. Gonna give it a try and let you know!
@marcelometal Done ;)
Hi @luccamendonca ,
I found a bug when I'm running the collector:
metal@blackhorse ~/work/politicos-go (feature/post-process-command) $ ./collector post-process candidacy-status
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/olhoneles/politicos-go/csv-collector/cmd.init.0.func1(0xc000227180, 0x141cff0, 0x0, 0x0, 0x0, 0x0)
/home/metal/work/politicos-go/csv-collector/cmd/post_process.go:29 +0xed
github.com/spf13/cobra.(*Command).execute(0xc000227180, 0x141cff0, 0x0, 0x0, 0xc000227180, 0x141cff0)
/home/metal/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:762 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0x124b560, 0xc00008e058, 0x0, 0x0)
/home/metal/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:852 +0x2fe
github.com/spf13/cobra.(*Command).Execute(...)
/home/metal/go/pkg/mod/github.com/spf13/cobra@v0.0.3/command.go:800
github.com/olhoneles/politicos-go/csv-collector/cmd.Execute(...)
/home/metal/work/politicos-go/csv-collector/cmd/root.go:20
main.main()
/home/metal/work/politicos-go/csv-collector/main.go:14 +0x32
Maybe you can fix it with:
metal@blackhorse ~/work/politicos-go (feature/post-process-command) $ git diff
diff --git a/csv-collector/cmd/post_process.go b/csv-collector/cmd/post_process.go
index 936bfe4..75d2975 100644
--- a/csv-collector/cmd/post_process.go
+++ b/csv-collector/cmd/post_process.go
@@ -26,8 +26,7 @@ func init() {
postProcessCmd.AddCommand(&cobra.Command{
Use: runningStep,
RunE: func(cmd *cobra.Command, args []string) error {
- subCmd := args[0]
- log.Debugf("Post-processing '%s'...", subCmd)
+ log.Debugf("Post-processing '%s'...", cmd)
return postProcessFunc()
},
})
My bad about the debug! Seems like I forgot to run the code before pushing :roll_eyes:
(Still not done, though!)
@marcelometal Now goes! (Agora vai!)
thank you @luccamendonca
closes #3