Skip to content

Commit

Permalink
Adicionar parâmetros
Browse files Browse the repository at this point in the history
debug e trace
  • Loading branch information
dude333 committed Sep 18, 2023
1 parent 558d779 commit f66601e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
6 changes: 1 addition & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

package main

import (
"github.com/dude333/rapinav2/pkg/progress"
)
// import "github.com/pkg/profile"

func main() {
// defer profile.Start().Stop()
progress.SetDebug(true)
progress.SetTrace(true)

Execute()
}
4 changes: 4 additions & 0 deletions cmd/relatorio.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func criarRelatório(empresa rapina.Empresa, dfp *contabil.DemonstraçãoFinance
}()

// DADOS CONSOLIDADOS
progress.Running("Relatório de dados consolidados")
itr, err := dfp.RelatórioTrimestal(empresa.CNPJ, true)
if err != nil {
progress.Fatal(err)
Expand All @@ -91,8 +92,10 @@ func criarRelatório(empresa rapina.Empresa, dfp *contabil.DemonstraçãoFinance
}
excelReport(x, rapina.UnificarContasSimilares(itr), !flags.relatorio.crescente)
}
progress.RunOK()

// DADOS INDIVIDUAIS
progress.Running("Relatório de dados individual")
itr, err = dfp.RelatórioTrimestal(empresa.CNPJ, false)
if err != nil {
progress.Fatal(err)
Expand All @@ -104,6 +107,7 @@ func criarRelatório(empresa rapina.Empresa, dfp *contabil.DemonstraçãoFinance
}
excelReport(x, rapina.UnificarContasSimilares(itr), !flags.relatorio.crescente)
}
progress.RunOK()

// Salva planilha
if err := x.file.SaveAs(filename); err != nil {
Expand Down
25 changes: 15 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
)

var flags = struct {
verbose bool
debug bool
trace bool
cfgFile string
atualizar flagsAtualizar
relatorio flagsRelatorio
dataSrc string // banco de dados sqlite (ex.: "file:/var/local/rapina.db")
Expand All @@ -31,8 +33,6 @@ const (
tempDirDefault = ".dados" + string(os.PathSeparator)
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "rapinav2",
Expand All @@ -42,6 +42,10 @@ var rootCmd = &cobra.Command{
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
// Run: func(cmd *cobra.Command, args []string) {
// progress.SetDebug(flags.debug)
// progress.SetTrace(flags.trace)
// },
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand All @@ -56,11 +60,9 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)

// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", `arquivo de configuração (default = ./`+configFileName+`)`)
rootCmd.PersistentFlags().StringVar(&flags.cfgFile, "config", "", `arquivo de configuração (default = ./`+configFileName+`)`)
rootCmd.PersistentFlags().BoolVarP(&flags.debug, "debug", "g", false, "Mostrar logs de depuração")
rootCmd.PersistentFlags().BoolVarP(&flags.trace, "trace", "t", false, "Mostrar logs de rastreamento")

str := `Uso:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
Expand Down Expand Up @@ -91,9 +93,12 @@ Use "{{.CommandPath}} [comando] --help" para mais informações sobre um comando

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
progress.SetDebug(flags.debug)
progress.SetTrace(flags.trace)

if flags.cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
viper.SetConfigFile(flags.cfgFile)
} else {
viper.AddConfigPath(".")
viper.SetConfigName(configFileName)
Expand Down

0 comments on commit f66601e

Please sign in to comment.