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: v3 #69

Merged
merged 4 commits into from
Jul 1, 2023
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
44 changes: 41 additions & 3 deletions cmd/qpm/internal/cmd/aquifer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"time"

"github.com/anoriqq/qpm"
"github.com/anoriqq/qpm/cmd/qpm/internal/config"
"github.com/anoriqq/qpm/cmd/qpm/internal/git"
"github.com/spf13/cobra"
Expand All @@ -20,6 +21,8 @@ var aquiferCmd = &cobra.Command{
}

func init() {
var aquiferPath string

aquiferPullCmd := &cobra.Command{
Use: "pull",
Short: "Get aquifer form remote repository",
Expand All @@ -34,8 +37,14 @@ func init() {
return err
}

oldDir := fmt.Sprintf("%s.old_%s", c.AquiferPath, time.Now().Format("20060102150405"))
if err := os.Rename(c.AquiferPath, oldDir); err != nil && !os.IsNotExist(err) {
if aquiferPath != "" {
c.AquiferPath = aquiferPath
}

aquiferPath := os.ExpandEnv(c.AquiferPath)

oldDir := fmt.Sprintf("%s.old_%s", aquiferPath, time.Now().Format("20060102150405"))
if err := os.Rename(aquiferPath, oldDir); err != nil && !os.IsNotExist(err) {
return err
}

Expand All @@ -44,13 +53,42 @@ func init() {
return err
}

if err = cl.Clone(c.AquiferPath, c.AquiferRemote.String()); err != nil {
if err = cl.Clone(aquiferPath, c.AquiferRemote.String()); err != nil {
return err
}

return nil
},
}

aquiferValidateCmd := &cobra.Command{
Use: "validate",
Short: "validate specific stratum of aquifer",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
path, err := config.InitConfigFile()
if err != nil {
return err
}

c, err := config.ReadConfig(path)
if err != nil {
return err
}

if aquiferPath != "" {
c.AquiferPath = aquiferPath
}

if _, err := qpm.ReadStratum(c, args[0]); err != nil {
return err
}

return nil
},
}

aquiferCmd.PersistentFlags().StringVarP(&aquiferPath, "aquifer", "a", "", "Aquifer directory path")
aquiferCmd.AddCommand(aquiferPullCmd)
aquiferCmd.AddCommand(aquiferValidateCmd)
}
4 changes: 2 additions & 2 deletions cmd/qpm/internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func init() {
},
}

configCmd.Flags().BoolVarP(&isInit, "init", "i", false, "Interalcive inisialization")
configCmd.Flags().BoolVarP(&isInit, "init", "i", false, "Interactive initialisation")
configCmd.Flags().BoolVarP(&isClear, "clear", "", false, "Clear config file")
rootCmd.AddCommand(configCmd)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func SurveyGitHubUsername(current *string) (string, error) {
}

func SurveyGitHubToken(current *string) (string, error) {
msg := "Please enter GitHub access token. If nothing is enterd, the current config will be taken over."
msg := "Please enter GitHub access token. If nothing is entered, the current config will be taken over."

v, err := survey.AskOnePassword(msg)
if err != nil {
Expand Down
35 changes: 33 additions & 2 deletions cmd/qpm/internal/cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package cmd

import (
"bufio"
"fmt"
"os"

"github.com/anoriqq/qpm"
"github.com/anoriqq/qpm/cmd/qpm/internal/config"
"github.com/anoriqq/qpm/cmd/qpm/internal/survey"
"github.com/spf13/cobra"
)

Expand All @@ -11,7 +16,7 @@ func init() {

installCmd := &cobra.Command{
Use: "install",
Short: "Install specifc package",
Short: "Install specific package",
Example: ` # Install foo package
qpm install foo`,
Args: cobra.RangeArgs(1, 2),
Expand All @@ -35,10 +40,36 @@ func init() {
return err
}

return qpm.Execute(c, s, qpm.Install)
if alreadyInstalled, err := qpm.IsAlreadyInstalled(s); err != nil {
return err
} else {
if alreadyInstalled {
if v, err := SurveyForceInstall(s.Name); err != nil {
return err
} else {
if !v {
fmt.Println("install canceled")
return nil
}
}
}
}

return qpm.Execute(c, s, qpm.Install, bufio.NewWriter(os.Stdout), bufio.NewWriter(os.Stderr))
},
}

installCmd.PersistentFlags().StringVarP(&aquiferPath, "aquifer", "a", "", "Aquifer directory path")
rootCmd.AddCommand(installCmd)
}

func SurveyForceInstall(name string) (bool, error) {
msg := name + " is already installed. Do you want to force installation?"

v, err := survey.AskOneConfirm(msg, false)
if err != nil {
return false, err
}

return v, nil
}
7 changes: 5 additions & 2 deletions cmd/qpm/internal/cmd/uninstall.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cmd

import (
"bufio"
"os"

"github.com/anoriqq/qpm"
"github.com/anoriqq/qpm/cmd/qpm/internal/config"
"github.com/spf13/cobra"
Expand All @@ -11,7 +14,7 @@ func init() {

uninstallCmd := &cobra.Command{
Use: "uninstall",
Short: "Unnstall specifc package",
Short: "Uninstall specific package",
Example: ` # Uninstall foo package
qpm uninstall foo`,
Args: cobra.RangeArgs(1, 2),
Expand All @@ -35,7 +38,7 @@ func init() {
return err
}

return qpm.Execute(c, s, qpm.Uninstall)
return qpm.Execute(c, s, qpm.Uninstall, bufio.NewWriter(os.Stdout), bufio.NewWriter(os.Stderr))
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/qpm/internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/go-git/go-git/v5"
ghttp "github.com/go-git/go-git/v5/plumbing/transport/http"
gHTTP "github.com/go-git/go-git/v5/plumbing/transport/http"
)

type client struct {
Expand All @@ -17,7 +17,7 @@ type client struct {
func (c *client) Clone(path, url string) error {
o := &git.CloneOptions{
URL: url,
Auth: &ghttp.BasicAuth{
Auth: &gHTTP.BasicAuth{
Username: c.username,
Password: c.accessToken,
},
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/stretchr/testify v1.8.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
Loading
Loading