Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aquifer-dir arg to install cmd #17

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion internal/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"errors"

"github.com/anoriqq/qpm/internal/config"
"github.com/anoriqq/qpm/internal/service/aquifer"
"github.com/spf13/cobra"
)
Expand All @@ -13,8 +14,11 @@ var installCmd = &cobra.Command{
RunE: installRun,
}

var aquiferDir string

func init() {
rootCmd.AddCommand(installCmd)
installCmd.PersistentFlags().StringVarP(&aquiferDir, "aquifer-dir", "d", "", "aquifer dir")
}

func installRun(_ *cobra.Command, args []string) error {
Expand All @@ -23,7 +27,7 @@ func installRun(_ *cobra.Command, args []string) error {
return err
}

return aquifer.Install(pkgName)
return aquifer.Install(getAquiferDir(), pkgName)
}

func getPkgName(args []string) (string, error) {
Expand All @@ -33,3 +37,11 @@ func getPkgName(args []string) (string, error) {

return args[0], nil
}

func getAquiferDir() string {
if len(aquiferDir) != 0 {
return aquiferDir
}

return config.Cfg.AquiferDir
}
23 changes: 19 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,21 @@ func Load() error {
return nil
}

const (
ConfigNameAquiferDir = "AquiferDir"
ConfigNameAquiferRepoURL = "AquiferRepoURL"
ConfigNameGithubUsername = "GitHubUsername"
ConfigNameGithubAccessToken = "GitHubAccessToken"
)

// aquifer dir

func hasAquiferDir() bool {
return len(Cfg.AquiferDir) != 0
}

func SetAquiferDir(aquiferDir string) error {
viper.Set("AquiferDir", aquiferDir)
viper.Set(ConfigNameAquiferDir, aquiferDir)

err := viper.WriteConfig()
if err != nil {
Expand All @@ -98,12 +107,14 @@ func SetAquiferDir(aquiferDir string) error {
return viper.Unmarshal(&Cfg)
}

// aquifer repo url

func hasAquiferRepoURL() bool {
return len(Cfg.AquiferRepoURL) != 0
}

func SetAquiferRepoURL(aquiferRepoURL string) error {
viper.Set("AquiferRepoURL", aquiferRepoURL)
viper.Set(ConfigNameAquiferRepoURL, aquiferRepoURL)

err := viper.WriteConfig()
if err != nil {
Expand All @@ -113,12 +124,14 @@ func SetAquiferRepoURL(aquiferRepoURL string) error {
return viper.Unmarshal(&Cfg)
}

// github username

func hasGitHubUsername() bool {
return len(Cfg.GitHubUsername) != 0
}

func SetGitHubUsername(githubUsername string) error {
viper.Set("GitHubUsername", githubUsername)
viper.Set(ConfigNameGithubUsername, githubUsername)

err := viper.WriteConfig()
if err != nil {
Expand All @@ -128,12 +141,14 @@ func SetGitHubUsername(githubUsername string) error {
return viper.Unmarshal(&Cfg)
}

// github access token

func hasGitHubAccessToken() bool {
return len(Cfg.GitHubAccessToken) != 0
}

func SetGitHubAccessToken(githubAccessToken string) error {
viper.Set("GitHubAccessToken", githubAccessToken)
viper.Set(ConfigNameGithubAccessToken, githubAccessToken)

err := viper.WriteConfig()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/service/aquifer/aquifer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ type Aquifer struct {
Uninstall map[string]Plan
}

func Install(pkgName string) error {
func Install(aquiferDir, pkgName string) error {
err := config.SetCfgWithSurvey(
config.SetAquiferDirWithSurvey,
)
if err != nil {
return err
}

aquiferPath, err := getAquiferPath(config.Cfg.AquiferDir, pkgName)
aquiferPath, err := getAquiferPath(aquiferDir, pkgName)
if err != nil {
return err
}
Expand Down