Skip to content

Commit

Permalink
Log prefix and small improvements (#3)
Browse files Browse the repository at this point in the history
* fix link

* rename main file

* catch err once

* print prefix

* prefix

* remove unneeded function
  • Loading branch information
mertd authored Aug 29, 2021
1 parent adf3cf0 commit 640052c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ The goal is to provide disk cleaning functionality like BleachBit, but in a zero

`topclean` is intended to be executed when you are running low on disk space and you are sure that deleting temporary files, caches, files marked for deletion (e.g. recycle bin) etc. is safe.

Until builds are provided, you need to run `go run main.go`.
Until builds are provided, you need to run `go run topclean.go`.

## Licence

[MIT](LICENCE.md)
[MIT](LICENCE)
26 changes: 11 additions & 15 deletions main.go → topclean.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import (
"os/exec"
)

var prefix = "[topclean] "
var apps = []App{
{"scoop", "scoop", []string{"cleanup", "*"}},
{"npm", "npm", []string{"cache", "clean", "--force"}},
{"yarn", "yarn", []string{"cache", "clean"}},
{"cleanmgr", "cleanmgr", []string{"/d", "c", "/verylowdisk"}},
}

func main() {
fmt.Print("topclean\n\n")
apps := getApps()
fmt.Println(prefix + "Starting!")
for i := 0; i < len(apps); i++ {
app := apps[i]
err := clean(app)
catch(err)
}
fmt.Print("\ndone\n")
fmt.Println(prefix + "Done!")
}

type App struct {
Expand All @@ -23,24 +30,13 @@ type App struct {
args []string
}

func getApps() []App {
apps := []App{
{"scoop", "scoop", []string{"cleanup", "*"}},
{"npm", "npm", []string{"cache", "clean", "--force"}},
{"yarn", "yarn", []string{"cache", "clean"}},
{"cleanmgr", "cleanmgr", []string{"/d", "c", "/verylowdisk"}},
}
return apps
}

func clean(app App) error {
fmt.Println("Cleaning " + app.name)
fmt.Println(prefix + "Cleaning " + app.name)
var stdout, stderr bytes.Buffer
cmd := exec.Command(app.cmd, app.args...)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
catch(err)
cmdLog(stdout.String(), stderr.String())
return err
}
Expand Down

0 comments on commit 640052c

Please sign in to comment.