-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (50 loc) · 1.12 KB
/
main.go
File metadata and controls
57 lines (50 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
"pm/internal/detector"
"pm/internal/executor"
"pm/internal/translator"
"pm/internal/ui"
"pm/internal/version"
)
func main() {
var rootCmd = &cobra.Command{
Use: "pm",
Short: "A universal package manager wrapper",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 && (args[0] == "-v" || args[0] == "--version") {
fmt.Println(version.GetVersion())
return
}
pm, err := detector.Detect()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
if len(args) == 0 {
script, err := ui.ShowScriptPrompt()
if err != nil {
if err.Error() != "cancelled" {
fmt.Fprintln(os.Stderr, err)
}
return
}
executor.Run(pm, translator.Commands.Run, script.Name)
return
}
tr := translator.New(pm)
translated := tr.Translate(pm, args)
if err := executor.Execute(pm, translated); err != nil {
fmt.Fprintln(os.Stderr, err)
}
},
Args: cobra.ArbitraryArgs,
}
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}