Skip to content

Commit 56514e8

Browse files
committed
Simplified Installing And Removing.
1 parent caeeb2c commit 56514e8

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/commands/remove.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"bread/src/helpers/utils"
66
"os"
7+
"strings"
78
)
89

910
type RemoveCmd struct {
@@ -12,7 +13,7 @@ type RemoveCmd struct {
1213
}
1314

1415
// Function which will be executed when `remove` is called.
15-
func (cmd *RemoveCmd) Run(*Context) (err error) {
16+
func (cmd *RemoveCmd) Run() (err error) {
1617
registry, err := utils.OpenRegistry()
1718
if err != nil {
1819
return err
@@ -21,6 +22,10 @@ func (cmd *RemoveCmd) Run(*Context) (err error) {
2122

2223
registry.Update()
2324

25+
if len(strings.Split(cmd.Target, "/")) < 2 {
26+
cmd.Target = cmd.Target + "/" + cmd.Target;
27+
}
28+
2429
entry, ok := registry.Lookup(cmd.Target)
2530
if !ok {
2631
return fmt.Errorf("application not found \"" + cmd.Target + "\"")

src/helpers/repos/github.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,22 @@ type GitHubRepo struct {
1818
// Function which parses string to a github repo information, adn returns a object and error (if any)
1919
func NewGitHubRepo(target string) (repo Repo, err error) {
2020
repo = &GitHubRepo{}
21-
var targetParts []string;
2221

23-
if strings.HasPrefix(target, "gh:") {
24-
// Take the `gh:user/repo` Remove "gh:" and split `user` and `repo`
25-
targetParts = strings.Split(target[3:], "/")
26-
} else {
27-
// Take the `gh:user/repo` and split `user` and `repo`
28-
targetParts = strings.Split(target, "/")
29-
}
22+
// Take the `user/repo` and split `user` and `repo`
23+
targetParts := strings.Split(target, "/")
24+
ghSource := GitHubRepo{}
3025

3126
targetPartsLen := len(targetParts)
3227
if targetPartsLen < 2 {
33-
return repo, InvalidTargetFormat
34-
}
35-
36-
ghSource := GitHubRepo{
37-
User: targetParts[0],
38-
Project: targetParts[1],
28+
ghSource = GitHubRepo{
29+
User: targetParts[0],
30+
Project: targetParts[0],
31+
}
32+
} else {
33+
ghSource = GitHubRepo{
34+
User: targetParts[0],
35+
Project: targetParts[1],
36+
}
3937
}
4038

4139
if targetPartsLen > 2 {
@@ -51,7 +49,7 @@ func NewGitHubRepo(target string) (repo Repo, err error) {
5149

5250
// Function to get the github repo id from the repo information
5351
func (g GitHubRepo) Id() string {
54-
id := "gh:" + g.User + "/" + g.Project
52+
id := g.User + "/" + g.Project
5553

5654
return id
5755
}

src/helpers/utils/util.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import (
2020
"path/filepath"
2121
)
2222

23+
type BinaryUrl struct {
24+
FileName string
25+
Url string
26+
}
27+
2328
func MakeApplicationsDirPath() (string, error) {
2429
usr, err := user.Current()
2530
if err != nil {
@@ -68,11 +73,6 @@ func DownloadAppImage(url string, filePath string) error {
6873
return err
6974
}
7075

71-
type BinaryUrl struct {
72-
FileName string
73-
Url string
74-
}
75-
7676
func PromptBinarySelection(downloadLinks []BinaryUrl) (result *BinaryUrl, err error) {
7777
if len(downloadLinks) == 1 {
7878
return &downloadLinks[0], nil

0 commit comments

Comments
 (0)