#8 delete cobra, add parsing .netrc

This commit is contained in:
Gorbunov Kirill Andreevich
2024-03-31 14:49:40 +03:00
parent 7bb53c8ef1
commit 4fc2cb0a5f
6 changed files with 34 additions and 20 deletions

View File

@@ -33,7 +33,8 @@ func NewCheckUpdateCommand() *cobra.Command {
Short: "CheckUpdate collects a list of dependencies with the latest updates.",
Long: `CheckUpdate collects a list of dependencies with the latest updates.`,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("checkupdate called")
logger.Info(ctx, "CheckUpdate called")
path := "."
if len(os.Args) > 1 {
path = os.Args[1]

View File

@@ -6,10 +6,12 @@ package cli
import (
"context"
"fmt"
"os"
"path/filepath"
"git.unistack.org/unistack-org/pkgdash/internal/configcli"
"git.unistack.org/unistack-org/pkgdash/internal/source"
"git.unistack.org/unistack-org/pkgdash/internal/source/github"
"github.com/spf13/cobra"
yamlcodec "go.unistack.org/micro-codec-yaml/v4"
envconfig "go.unistack.org/micro-config-env/v4"
@@ -23,7 +25,7 @@ import (
// initCmd represents the init command
var initCmd = NewInitCommand()
var gitsource = source.SourceControl(nil)
var gitsource source.SourceControl = (*github.Github)(nil)
var cfg = configcli.NewConfig()
@@ -63,16 +65,18 @@ func NewInitCommand() *cobra.Command {
Short: "Init fills the config with data from the configuration file.",
Long: `Init fills the config with data from the configuration file.`,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init called")
logger.Info(ctx, "Init called")
var err error
lCfg := configcli.NewConfig()
if err = config.Load(ctx,
[]config.Config{
config.NewConfig(
config.Struct(cfg),
config.Struct(lCfg),
),
envconfig.NewConfig(
config.Struct(cfg),
config.Struct(lCfg),
),
},
config.LoadOverride(true),
@@ -82,12 +86,16 @@ func NewInitCommand() *cobra.Command {
for _, configDir := range configDirs {
for _, configFile := range configFiles {
logger.Info(ctx, fmt.Sprintf("path: %s", filepath.Join(configDir, configFile)))
path := filepath.Join(configDir, configFile)
if _, err = os.Stat(path); os.IsNotExist(err) {
continue
}
c := fileconfig.NewConfig(
config.AllowFail(false),
config.Struct(cfg),
config.Struct(lCfg),
options.Codec(yamlcodec.NewCodec()),
fileconfig.Path(".gitea/pkgdashcli.yaml"),
fileconfig.Path(path),
)
err = c.Init(options.Context(ctx))
if err != nil {
@@ -101,7 +109,7 @@ func NewInitCommand() *cobra.Command {
}
}
logger.Info(ctx, fmt.Sprintf("Load config... %s", cfg.Source.Repository))
logger.Info(ctx, fmt.Sprintf("Load config... \n %s", cfg))
if cfg.PullRequestBody == "" {
cfg.PullRequestBody = DefaultPullRequestBody
@@ -111,7 +119,11 @@ func NewInitCommand() *cobra.Command {
cfg.PullRequestTitle = DefaultPullRequestTitle
}
gitsource = source.NewSourceControl(*cfg)
gitsource = source.NewSourceControl(*lCfg)
logger.Info(ctx, fmt.Sprintf("Git: %s", gitsource.Name()))
cfg = lCfg
return nil
},

View File

@@ -35,8 +35,6 @@ func init() {
func NewListCommand() *cobra.Command {
ctx := context.Background()
logger.Info(ctx, "RequestList start")
cmd := &cobra.Command{
Use: "list",
Short: "Update allows you to start the process of creating a PR in the repository",
@@ -45,6 +43,9 @@ Update allows you to start the process of creating a PR in the repository.
Use the -a flag to update all dependencies or -m flag a specific module.
`,
RunE: func(cmd *cobra.Command, args []string) error {
logger.Info(ctx, "RequestList start")
if gitsource == nil {
return errSourceNil
}
@@ -54,8 +55,9 @@ Use the -a flag to update all dependencies or -m flag a specific module.
}
prList = make(map[string]map[string]string)
logger.Info(ctx, fmt.Sprintf("Load config... \n %s", cfg))
for _, branch := range cfg.Branches {
logger.Info(ctx, fmt.Sprintf("Start getting pr for %s", branch))
rMap, err := gitsource.RequestList(ctx, branch)
if err != nil {
return err
@@ -65,6 +67,8 @@ Use the -a flag to update all dependencies or -m flag a specific module.
logger.Info(ctx, fmt.Sprintf("for %s:\n%s", branch, rMap))
}
logger.Info(ctx, "Successful getting pull requests")
return nil
},
}