olhoneles / politicos-go

API com todos os candidatos Brasileiros!
https://politicos.olhoneles.org
GNU Affero General Public License v3.0
3 stars 1 forks source link

Created post-process command #4

Closed luccamendonca closed 3 years ago

luccamendonca commented 4 years ago

closes #3

luccamendonca commented 4 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:

Anyway, the post-process command seems fairly usable already :)

Lemme know if there's anything you may want to change ;)

marcelometal commented 4 years ago

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?

luccamendonca commented 4 years ago

I think it should be possible, indeed. Gonna give it a try and let you know!

luccamendonca commented 3 years ago

@marcelometal Done ;)

marcelometal commented 3 years ago

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()
                        },
                })
luccamendonca commented 3 years ago

My bad about the debug! Seems like I forgot to run the code before pushing :roll_eyes:

luccamendonca commented 3 years ago

(Still not done, though!)

luccamendonca commented 3 years ago

@marcelometal Now goes! (Agora vai!)

marcelometal commented 3 years ago

thank you @luccamendonca