aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlawl <github@dumbinter.net>2021-06-04 12:14:39 +0200
committerlawl <github@dumbinter.net>2021-06-04 12:14:39 +0200
commit077b4763fef6f8c07a04dd36c6deef2c1f3af580 (patch)
treecad601a4a59bbc56e295ae4e7a65a1f338c11b5f
parent809f184e875ce012b7e75c6def2ec56aebd5cf94 (diff)
downloadnoisetorch-077b4763fef6f8c07a04dd36c6deef2c1f3af580.tar.gz
noisetorch-077b4763fef6f8c07a04dd36c6deef2c1f3af580.zip
CLI: Cleanup temp files on exit
Fixes #135
-rw-r--r--cli.go33
1 files changed, 19 insertions, 14 deletions
diff --git a/cli.go b/cli.go
index d8b09ee..7e026ff 100644
--- a/cli.go
+++ b/cli.go
@@ -39,15 +39,15 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
if opt.setcap {
err := makeBinarySetcapped()
if err != nil {
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
- os.Exit(0)
+ cleanupExit(librnnoise, 0)
}
paClient, err := pulseaudio.NewClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Couldn't create pulseaudio client: %v\n", err)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
defer paClient.Close()
@@ -77,7 +77,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
fmt.Printf("\tDevice Name: %s\n\tDevice ID: %s\n\n", sinks[i].Name, sinks[i].ID)
}
- os.Exit(0)
+ cleanupExit(librnnoise, 0)
}
if opt.threshold > 0 {
@@ -93,9 +93,9 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
err := unloadSupressor(&ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "Error unloading PulseAudio Module: %+v\n", err)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
- os.Exit(0)
+ cleanupExit(librnnoise, 0)
}
if opt.loadInput {
@@ -105,7 +105,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
defaultSource, err := getDefaultSourceID(paClient)
if err != nil {
fmt.Fprintf(os.Stderr, "No source specified to load and failed to load default source: %+v\n", err)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
opt.sinkName = defaultSource
}
@@ -115,13 +115,13 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
err := loadSupressor(&ctx, &sources[i], &device{})
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading PulseAudio Module: %+v\n", err)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
- os.Exit(0)
+ cleanupExit(librnnoise, 0)
}
}
fmt.Fprintf(os.Stderr, "PulseAudio source not found: %s\n", opt.sinkName)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
if opt.loadOutput {
@@ -131,7 +131,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
defaultSink, err := getDefaultSinkID(paClient)
if err != nil {
fmt.Fprintf(os.Stderr, "No sink specified to load and failed to load default sink: %+v\n", err)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
opt.sinkName = defaultSink
}
@@ -141,13 +141,18 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
err := loadSupressor(&ctx, &device{}, &sinks[i])
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading PulseAudio Module: %+v\n", err)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
- os.Exit(0)
+ cleanupExit(librnnoise, 0)
}
}
fmt.Fprintf(os.Stderr, "PulseAudio sink not found: %s\n", opt.sinkName)
- os.Exit(1)
+ cleanupExit(librnnoise, 1)
}
}
+
+func cleanupExit(librnnoise string, exitCode int) {
+ removeLib(librnnoise)
+ os.Exit(exitCode)
+}