-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
106 lines (97 loc) · 2.68 KB
/
main.go
File metadata and controls
106 lines (97 loc) · 2.68 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// PROGRAM: DBIN
// MAINTAINER: IDIOT (xplshn)
// PURPOSE: Package manager done right
// DESCRIPTION: A package manager that uses one-file packages (statically linked binaries, self-contained binaries)
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/urfave/cli/v3"
)
const (
version = 1.7
maxCacheSize = 15
binariesToDelete = 5
// --------------------------------
extraVerbose uint8 = 4
normalVerbosity uint8 = 3
silentVerbosityWithErrors uint8 = 2
extraSilent uint8 = 1
// -------------------------------
)
var verbosityLevel = normalVerbosity
func main() {
app := &cli.Command{
Name: "dbin",
Usage: "The easy to use, easy to get, software distribution system",
Version: strconv.FormatFloat(version, 'f', -1, 32),
Description: "The easy to use, easy to get, software distribution system",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Usage: "Run in extra verbose mode",
},
&cli.BoolFlag{
Name: "silent",
Usage: "Run in silent mode, only errors will be shown",
},
&cli.BoolFlag{
Name: "extra-silent",
Usage: "Run in extra silent mode, suppressing almost all output",
},
},
Before: func(ctx context.Context, c *cli.Command) (context.Context, error) {
switch {
case c.Bool("extra-silent"):
verbosityLevel = extraSilent
case c.Bool("silent"):
verbosityLevel = silentVerbosityWithErrors
case c.Bool("verbose"):
verbosityLevel = extraVerbose
}
return nil, nil
},
Commands: []*cli.Command{
installCommand(),
removeCommand(),
listCommand(),
searchCommand(),
infoCommand(),
runCommand(),
updateCommand(),
configCommand(),
},
EnableShellCompletion: true,
}
pathDirs := strings.Split(os.Getenv("PATH"), string(os.PathListSeparator))
found := false
for _, dir := range pathDirs {
if !found || len(pathDirs) == 0 {
if dir == "." || dir == ".." {
continue
}
if _, err := os.Stat(filepath.Join(dir, filepath.Base(os.Args[0]))); err == nil {
found = true
break
}
}
}
if err := app.Run(context.Background(), os.Args); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if !found {
fmt.Fprintf(os.Stderr, "\n%swarning%s: dbin not in $PATH\n", yellowColor, resetColor)
}
}
func fetchRepoIndex(config *config) ([]binaryEntry, error) {
uRepoIndex, err := decodeRepoIndex(config)
if err != nil {
return nil, fmt.Errorf("%v: Consider checking if DBIN_NOCONFIG=1 works, if so, consider modifying your config, your repository URLs may be outdated.\nAlso consider removing dbin's cache if the above fails", err)
}
return uRepoIndex, nil
}