Skip to content

Commit

Permalink
install: fix install command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tch1b0 committed Aug 1, 2022
1 parent 6b075b6 commit 04165ce
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
10 changes: 3 additions & 7 deletions pkg/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ func install(ctx *cli.Context) error {
}

for _, repo := range dependencies.Slice() {
if config.HasDependency(repo) {
alreadyInstalled(repo)
} else if err = installDependency(&config, paths, repo, false); err != nil {
if err = installDependency(&config, paths, repo, false); err != nil {
return err
}
}
Expand All @@ -38,16 +36,15 @@ func installAllDependencies(config *utility.PpmConfig, paths utility.Paths) erro
return err
}
}
utility.PrintDone()
return nil
}

func installDependency(config *utility.PpmConfig, paths utility.Paths, dependency string, isSubDependency bool) error {
dependency, version := utility.GetVersionOrNot(dependency)
if !isSubDependency {
fmt.Printf("\rinstalling %s\n", color.YellowString(utility.GetPluginName(dependency)))
fmt.Printf("\rinstalling %s\n", color.YellowString(utility.GetPluginIdentifier(dependency)))
} else {
fmt.Printf("\t -> installing %s\n", color.YellowString(utility.GetPluginName(dependency)))
fmt.Printf("\t -> installing %s\n", color.YellowString(utility.GetPluginIdentifier(dependency)))
}
loadAnim := utility.StartLoading()

Expand All @@ -57,7 +54,6 @@ func installDependency(config *utility.PpmConfig, paths utility.Paths, dependenc
if err != nil {
if err.Error() == "repository already exists" {
alreadyInstalled(dependency)
return nil
} else {
installError(dependency)
return err
Expand Down
5 changes: 3 additions & 2 deletions pkg/commands/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func uninstallAllDependencies(config *utility.PpmConfig, paths utility.Paths, ha
}

func uninstallDependency(config *utility.PpmConfig, paths utility.Paths, dependency string, isSubDependency bool) error {
dep := utility.GetPluginName(dependency)
dep := utility.GetPluginIdentifier(dependency)
if !isSubDependency {
fmt.Println("\runinstalling", color.YellowString(dep))
} else {
Expand All @@ -73,7 +73,8 @@ func uninstallDependency(config *utility.PpmConfig, paths utility.Paths, depende
}

// path: root/addons/dependency
err = os.RemoveAll(path.Join(paths.Addons, dep))
fmt.Println(path.Join(paths.Addons, utility.GetPluginName(dep)))
err = os.RemoveAll(path.Join(paths.Addons, utility.GetPluginName(dep)))
loadAnim.Stop()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/utility/ppmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (ppm *PpmConfig) RemoveAllDependencies() {

// remove an item safely from the Dependencies property by its name
func (ppm *PpmConfig) RemoveSubDependency(dependency string) {
dependency = GetPluginName(dependency)
dependency = GetPluginIdentifier(dependency)
ppm.SubDependencies = Filter(ppm.SubDependencies, func(item string, _ int) bool {
return item != dependency
})
Expand All @@ -49,7 +49,7 @@ func (ppm *PpmConfig) RemoveSubDependency(dependency string) {

// remove an item safely from the sub-dependencies property by its name
func (ppm *PpmConfig) RemoveDependency(dependency string) {
dependency = GetPluginName(dependency)
dependency = GetPluginIdentifier(dependency)
ppm.Dependencies = Filter(ppm.Dependencies, func(item string, _ int) bool {
return item != dependency
})
Expand Down
11 changes: 10 additions & 1 deletion pkg/utility/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func PrintDone() {
fmt.Print(color.GreenString("\rdone\n"))
}

func GetPluginName(name string) string {
func GetPluginIdentifier(name string) string {
if strings.HasPrefix(name, "https://") {
urlParts := strings.Split(name, "/")
return urlParts[len(urlParts)-1]
Expand All @@ -86,6 +86,15 @@ func GetPluginName(name string) string {
}
}

func GetPluginName(name string) string {
s := GetPluginIdentifier(name)
if strings.Contains(s, "/") {
return strings.Split(s, "/")[1]
} else {
return s
}
}

func GetPathsAndConfig() (Paths, PpmConfig, error) {
paths, err := CreatePathsFromCwd()
if err != nil {
Expand Down

0 comments on commit 04165ce

Please sign in to comment.