Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Commit ecec127

Browse files
committed
Fixed golangci-lint errors and added new option for spinners
1 parent 2aec700 commit ecec127

22 files changed

+176
-93
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"Deps",
1818
"devmasx",
1919
"dont",
20+
"exhaustruct",
2021
"forbidigo",
2122
"gmake",
2223
"GOARCH",

cmds.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
// List installed packages
9+
// List installed packages.
1010
func listPkgs() {
1111
installedPkgs := make([]string, 0)
1212
files := dirContents(infoPath, "An error occurred while getting list of installed packages")
@@ -23,7 +23,7 @@ func listPkgs() {
2323
rawLog(strings.Join(installedPkgs, "\n") + "\n")
2424
}
2525

26-
// Gets info for a package
26+
// Gets info for a package.
2727
func infoPkg(pkgName string) {
2828
pkg := loadPkg(getPkgInfo(pkgName, isValidURL(pkgName)), pkgName)
2929

@@ -58,7 +58,7 @@ func infoPkg(pkgName string) {
5858
getNotes(pkg)
5959
}
6060

61-
// Removes data for packages
61+
// Removes data for packages.
6262
func rmData(pkgNames []string) {
6363
log(3, "Warning: This will remove the data for the selected packages stored in %s", mainPath)
6464
log(3, "This will %snot%s run the uninstall commands.", textFx.Bold, RESETCOL)
@@ -82,7 +82,7 @@ func rmData(pkgNames []string) {
8282
log(0, "Successfully deleted data.")
8383
}
8484

85-
// Searches for a package
85+
// Searches for a package.
8686
func search(query string) {
8787
initDirs(false)
8888
loadConfig()
@@ -97,7 +97,7 @@ func search(query string) {
9797
}
9898
}
9999

100-
// Lists all packages in the repos
100+
// Lists all packages in the repos.
101101
func listAll() {
102102
initDirs(false)
103103
loadConfig()
@@ -112,7 +112,7 @@ func listAll() {
112112
}
113113
}
114114

115-
// Fetches and displays system & go info
115+
// Fetches and displays system & go info.
116116
func fetch() {
117117
configExists := pathExists(configPath+"config.toml", "config file")
118118

@@ -185,7 +185,7 @@ func fetch() {
185185
}
186186
}
187187

188-
// Runs help2man for indiepkg
188+
// Runs help2man for indiepkg.
189189
func help2man() {
190190
log(1, "Compiling IndiePKG...")
191191

config.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type Progressbar struct {
4040
BarEnd string
4141
}
4242

43+
type Progress struct {
44+
CompileProgressIndicator string `toml:"compile_progress_indicator"`
45+
}
46+
4347
type Config struct {
4448
Paths Paths
4549

@@ -48,6 +52,8 @@ type Config struct {
4852
Progressbar Progressbar
4953

5054
Github Github
55+
56+
Progress Progress
5157
}
5258

5359
var config Config = Config{
@@ -73,9 +79,13 @@ var config Config = Config{
7379
"username",
7480
"token",
7581
},
82+
83+
Progress{
84+
"spinner",
85+
},
7686
}
7787

78-
// Loads & reads configuration file
88+
// Loads & reads configuration file.
7989
func loadConfig() {
8090
log(1, "Reading config file...")
8191

defText.go

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ username = ""
8686
# Github access token, this should not expire and have no permissions granted for security purposes.
8787
# Information about getting a token is available here. https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
8888
token = ""
89+
90+
# Configures other progress indicators
91+
[progress]
92+
93+
# Default: spinner. Valid values: spinner, dots
94+
compile_progress_indicator = "spinner"
8995
`
9096

9197
const defaultSources = `# Please only add sources you trust.

downloadURL.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"runtime"
66
)
77

8-
// Gets the URL to download for a package
8+
// Gets the URL to download for a package.
99
func getDownloadURL(pkg Package) string {
1010
debugLog("GOOS: %s. GOARCH: %s", runtime.GOOS, runtime.GOARCH)
1111

exec.go

+30-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"bufio"
55
"os/exec"
66
"strings"
7+
8+
"github.com/talwat/indiepkg/spinner"
79
)
810

9-
// Runs a command and prints the output to the terminal in real time
11+
// Runs a command and prints the output to the terminal in real time.
1012
func runCommandRealTime(workDir string, cmd string, args ...string) {
1113
cmdObj := exec.Command(cmd, args...)
1214
cmdObj.Dir = workDir
@@ -38,8 +40,26 @@ func runCommandRealTime(workDir string, cmd string, args ...string) {
3840
errorLogNewlineBefore(err, "An error occurred while running command")
3941
}
4042

41-
// Runs a command and displays dots to indicate progress
42-
func runCommandDot(workDir string, forceCmd bool, cmd string, args ...string) {
43+
// Runs a command and displays dots to indicate progress.
44+
func runCommandDot(commandName string, workDir string, forceCmd bool, cmd string, args ...string) {
45+
spinner := spinner.Spinner{ // nolint:exhaustruct
46+
Prefix: logType[1] + " Running command " + bolden(commandName) + " ",
47+
SpinnerArt: []string{
48+
textCol.Violet + "/" + RESETCOL,
49+
textCol.Violet + "|" + RESETCOL,
50+
textCol.Violet + "\\" + RESETCOL,
51+
textCol.Violet + "-" + RESETCOL,
52+
},
53+
}
54+
55+
debugLog("Progress indicator: %s", config.Progress.CompileProgressIndicator)
56+
57+
if config.Progress.CompileProgressIndicator == "dots" {
58+
logNoNewline(1, "Running command %s", bolden(commandName))
59+
} else {
60+
spinner.DisplaySpinner()
61+
}
62+
4363
parsedCmd := strings.TrimPrefix(cmd, "!(FORCE)! ")
4464
cmdObj := exec.Command(parsedCmd, args...)
4565
cmdObj.Dir = workDir
@@ -65,7 +85,11 @@ func runCommandDot(workDir string, forceCmd bool, cmd string, args ...string) {
6585
if debug {
6686
rawLogf(logType[5]+(" %s\n"), scanner.Text())
6787
} else {
68-
rawLog(textCol.Violet + "." + RESETCOL)
88+
if config.Progress.CompileProgressIndicator == "dots" {
89+
rawLog(textCol.Violet + "." + RESETCOL)
90+
} else {
91+
spinner.DisplaySpinner()
92+
}
6993
}
7094
}
7195

@@ -79,7 +103,7 @@ func runCommandDot(workDir string, forceCmd bool, cmd string, args ...string) {
79103
}
80104
}
81105

82-
// Runs a command
106+
// Runs a command.
83107
func runCommand(workDir string, cmd string, args ...string) (string, error) {
84108
cmdObj := exec.Command(cmd, args...)
85109
cmdObj.Dir = workDir
@@ -92,7 +116,7 @@ func runCommand(workDir string, cmd string, args ...string) (string, error) {
92116
return strings.TrimSuffix(string(data), "\n"), nil
93117
}
94118

95-
// Check if a command exists
119+
// Check if a command exists.
96120
func checkIfCommandExists(cmd string) bool {
97121
_, err := exec.LookPath(cmd)
98122

files.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import "strings"
44

5-
// Copies binaries to their proper location for a specific package
5+
// Copies binaries to their proper location for a specific package.
66
func copyBins(pkg Package, srcPath string) {
77
if pkg.Bin == nil { // Safeguard to prevent nil pointer dereference
88
return
@@ -27,7 +27,7 @@ func copyBins(pkg Package, srcPath string) {
2727
}
2828
}
2929

30-
// Copies manpages to their proper location for a specific package
30+
// Copies manpages to their proper location for a specific package.
3131
func copyManpages(pkg Package, srcPath string) {
3232
if len(pkg.Manpages) == 0 { // If package doesn't have manpages, return
3333
return

funcs.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
// Check if a package is installed
9+
// Check if a package is installed.
1010
func pkgExists(pkgName string) bool {
1111
pkgDispName := bolden(pkgName)
1212

@@ -25,7 +25,7 @@ func pkgExists(pkgName string) bool {
2525
}
2626
}
2727

28-
// Runs an array of commands
28+
// Runs an array of commands.
2929
func runCmds(cmds []string, pkg Package, path string, cmdsLabel string) {
3030
debugLog("Work dir: %s", path)
3131

@@ -35,14 +35,13 @@ func runCmds(cmds []string, pkg Package, path string, cmdsLabel string) {
3535
for _, cmd := range cmds {
3636
parsedCmd := strings.TrimPrefix(cmd, "!(FORCE)! ")
3737

38-
logNoNewline(1, "Running command %s", bolden(parsedCmd))
39-
runCommandDot(path, strings.HasPrefix(cmd, "!(FORCE)! "), strings.Split(parsedCmd, " ")[0], strings.Split(parsedCmd, " ")[1:]...)
38+
runCommandDot(parsedCmd, path, strings.HasPrefix(cmd, "!(FORCE)! "), strings.Split(parsedCmd, " ")[0], strings.Split(parsedCmd, " ")[1:]...)
4039
rawLog("\n")
4140
}
4241
}
4342
}
4443

45-
// Creates required directories and files
44+
// Creates required directories and files.
4645
func initDirs(reset bool) {
4746
if reset {
4847
confirm("y", "Are you sure you want to reset the directories? This will reset your custom configuration & sources file. (y/n)")
@@ -70,7 +69,7 @@ func initDirs(reset bool) {
7069
}
7170
}
7271

73-
// Gets dependencies
72+
// Gets dependencies.
7473
func getDeps(deps *Deps) []string {
7574
if deps != nil {
7675
fullDepsList := deps.All
@@ -100,7 +99,7 @@ func getPkgNameFromURL(url string) string {
10099
return strings.TrimSuffix(strings.Split(url, "/")[len(strings.Split(url, "/"))-1], ".json")
101100
}
102101

103-
// Checks if all dependencies of a package are installed
102+
// Checks if all dependencies of a package are installed.
104103
func checkDeps(pkg Package) {
105104
if pkgDispName := bolden(pkg.Name); !noDeps {
106105
log(1, "Getting dependencies for %s...", pkgDispName)
@@ -131,7 +130,7 @@ func checkDeps(pkg Package) {
131130
}
132131
}
133132

134-
// Checks if all file dependencies of a package are installed
133+
// Checks if all file dependencies of a package are installed.
135134
func checkFileDeps(pkg Package) {
136135
if pkgDispName := bolden(pkg.Name); !noDeps {
137136
log(1, "Getting file dependencies for %s...", pkgDispName)
@@ -162,7 +161,7 @@ func checkFileDeps(pkg Package) {
162161
}
163162
}
164163

165-
// Parse sources file
164+
// Parse sources file.
166165
func parseSources() []string {
167166
log(1, "Reading sources file...")
168167

@@ -189,15 +188,15 @@ func parseSources() []string {
189188
return finalList
190189
}
191190

192-
// Prints notes for a package
191+
// Prints notes for a package.
193192
func getNotes(pkg Package) {
194193
if len(pkg.Notes) > 0 {
195194
log(1, bolden("Important note!"))
196195
indent(strings.Join(pkg.Notes, "\n"))
197196
}
198197
}
199198

200-
// Displays a confirmation message when installing, uninstalling, etc... a package
199+
// Displays a confirmation message when installing, uninstalling, etc... a package.
201200
func displayPkgs(pkgNames []string, action string) {
202201
log(1, "Are you sure you would like to %s the following packages:", bolden(action))
203202

@@ -208,7 +207,7 @@ func displayPkgs(pkgNames []string, action string) {
208207
confirm("y", "(y/n)")
209208
}
210209

211-
// Checks if the user is root and suspends program if the user is root
210+
// Checks if the user is root and suspends program if the user is root.
212211
func checkRoot() {
213212
if isRoot() {
214213
if force || ignoreRoot {
@@ -221,13 +220,13 @@ func checkRoot() {
221220
}
222221
}
223222

224-
// Deletes temporary directory
223+
// Deletes temporary directory.
225224
func delTmp() {
226225
log(1, "Deleting temporary directory...")
227226
delPath(true, tmpPath, "An error occurred while deleting the temporary directory")
228227
}
229228

230-
// Fully initializes all things for IndiePKG to function
229+
// Fully initializes all things for IndiePKG to function.
231230
func fullInit() {
232231
chapLog("=>", "", "Initializing")
233232
checkRoot()

get.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"strings"
77
)
88

9-
// Writes a packages info to the proper location
9+
// Writes a packages info to the proper location.
1010
func writePkg(pkgName string, pkgFile string) {
1111
log(1, "Writing package info for %s...", bolden(pkgName))
1212
newFile(infoPath+pkgName+".json", pkgFile, "An error occurred while writing package information for %s", pkgName)
1313
}
1414

15-
// Finds a packages info in the repos
15+
// Finds a packages info in the repos.
1616
func findPkg(pkgName string) string {
1717
log(1, "Finding package %s...", bolden(pkgName))
1818

@@ -110,7 +110,7 @@ func findPkg(pkgName string) string {
110110
return ""
111111
}
112112

113-
// Gets a packages info from the internet
113+
// Gets a packages info from the internet.
114114
func getPkgFromNet(pkgName string) (Package, string) {
115115
packageFile := findPkg(pkgName)
116116

@@ -119,7 +119,7 @@ func getPkgFromNet(pkgName string) (Package, string) {
119119
return pkg, packageFile
120120
}
121121

122-
// Gets a packages info from a URL
122+
// Gets a packages info from a URL.
123123
func getPkgFromURL(pkgName string, url string) string {
124124
packageFile, statusCode, err := viewFile(url)
125125
errorLog(err, "An error occurred while getting package information for %s", bolden(pkgName))
@@ -131,7 +131,7 @@ func getPkgFromURL(pkgName string, url string) string {
131131
return packageFile
132132
}
133133

134-
// Downloads data for a package directly
134+
// Downloads data for a package directly.
135135
func doDirectDownload(pkg Package, srcPath string) {
136136
pkgDispName := bolden(pkg.Name)
137137

@@ -153,7 +153,7 @@ func doDirectDownload(pkg Package, srcPath string) {
153153
downloadFileWithProg(nameOfFile, url, "An error occurred while downloading file for %s", pkgDispName)
154154
}
155155

156-
// Gets info for a package
156+
// Gets info for a package.
157157
func getPkgInfo(pkgName string, isURL bool) string {
158158
var pkgFile string
159159

0 commit comments

Comments
 (0)