Skip to content

Commit 5f71f33

Browse files
committed
feat: Restructure the CMD package
1 parent 092a214 commit 5f71f33

File tree

13 files changed

+167
-144
lines changed

13 files changed

+167
-144
lines changed

cmd/install.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

cmd/install/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package install
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// Register registers install command.
12+
func Register(root *cobra.Command) {
13+
cmd := &cobra.Command{
14+
Use: "install [name of packages]",
15+
Aliases: []string{"i"},
16+
Short: "installs a package",
17+
Long: "Installing package(s) in DonyaOS",
18+
Args: cobra.MinimumNArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
leng := strconv.Itoa(len(args))
21+
fmt.Println("Installing " + leng + " package(s): " + strings.Join(args, " "))
22+
},
23+
}
24+
25+
root.AddCommand(cmd)
26+
}

cmd/purge.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

cmd/purge/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package purge
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// Register registers purge command.
12+
func Register(root *cobra.Command) {
13+
cmd := &cobra.Command{
14+
Use: "purge [name of packages]",
15+
Aliases: []string{"p"},
16+
Short: "removes all orphaned packages",
17+
Long: "Removing all orphaned package(s) in DonyaOS",
18+
Args: cobra.MinimumNArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
leng := strconv.Itoa(len(args))
21+
fmt.Println("Purging " + leng + " package(s): " + strings.Join(args, " "))
22+
},
23+
}
24+
25+
root.AddCommand(cmd)
26+
}

cmd/root.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/DonyaOS/PackageManager/cmd/install"
8+
"github.com/DonyaOS/PackageManager/cmd/purge"
9+
"github.com/DonyaOS/PackageManager/cmd/search"
710
"github.com/spf13/cobra"
811
)
912

10-
var cfgFile string
11-
12-
// rootCmd represents the base command when called without any subcommands
13-
var rootCmd = &cobra.Command{
14-
Use: "todo",
15-
Short: "A simple todo list made with golan",
16-
}
13+
// ExitFailure status code.
14+
const ExitFailure = 1
1715

1816
// Execute adds all child commands to the root command and sets flags appropriately.
1917
// This is called by main.main(). It only needs to happen once to the rootCmd.
2018
func Execute() {
21-
if err := rootCmd.Execute(); err != nil {
22-
fmt.Println(err)
23-
os.Exit(1)
19+
root := &cobra.Command{
20+
Use: "donya",
21+
Short: "Donya Package Manager/System",
22+
}
23+
24+
install.Register(root)
25+
purge.Register(root)
26+
search.Register(root)
27+
28+
if err := root.Execute(); err != nil {
29+
fmt.Printf("error: %s\n", err.Error())
30+
os.Exit(ExitFailure)
2431
}
2532
}

cmd/search.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

cmd/search/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package search
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// Register registers search command.
12+
func Register(root *cobra.Command) {
13+
cmd := &cobra.Command{
14+
Use: "search [name of packages]",
15+
Aliases: []string{"s"},
16+
Short: "searches for a package",
17+
Long: "Searching for a package(s) in DonyaOS",
18+
Args: cobra.MinimumNArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
leng := strconv.Itoa(len(args))
21+
fmt.Println("Searching for " + leng + " package(s): " + strings.Join(args, " "))
22+
},
23+
}
24+
25+
root.AddCommand(cmd)
26+
}

cmd/uninstall.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

cmd/uninstall/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// Register registers uninstall command.
12+
func Register(root *cobra.Command) {
13+
cmd := &cobra.Command{
14+
Use: "uninstall [name of packages]",
15+
Aliases: []string{"r", "remove"},
16+
Short: "removes a package",
17+
Long: "Removing package(s) in DonyaOS",
18+
Args: cobra.MinimumNArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
leng := strconv.Itoa(len(args))
21+
fmt.Println("Uninstalling " + leng + " package(s): " + strings.Join(args, " "))
22+
},
23+
}
24+
25+
root.AddCommand(cmd)
26+
}

cmd/update.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)