return exit code 1 on error

Fixes #132
This commit is contained in:
Nicola Murino
2020-06-20 14:30:46 +02:00
parent 8cb47817f6
commit b80abe6c05
12 changed files with 41 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
package cmd
import (
"os"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -44,6 +46,7 @@ Please take a look at the usage below to customize the options.`,
logger.DebugToConsole("Data provider successfully initialized")
} else {
logger.WarnToConsole("Unable to initialize data provider: %v", err)
os.Exit(1)
}
},
}

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"strconv"
"github.com/spf13/cobra"
@@ -42,6 +43,7 @@ Please take a look at the usage below to customize the startup options`,
err := winService.Install(serviceArgs...)
if err != nil {
fmt.Printf("Error installing service: %v\r\n", err)
os.Exit(1)
} else {
fmt.Printf("Service installed!\r\n")
}

View File

@@ -73,12 +73,12 @@ Please take a look at the usage below to customize the serving parameters`,
fi, err := os.Stat(portableGCSCredentialsFile)
if err != nil {
fmt.Printf("Invalid GCS credentials file: %v\n", err)
return
os.Exit(1)
}
if fi.Size() > 1048576 {
fmt.Printf("Invalid GCS credentials file: %#v is too big %v/1048576 bytes\n", portableGCSCredentialsFile,
fi.Size())
return
os.Exit(1)
}
creds, err := ioutil.ReadFile(portableGCSCredentialsFile)
if err != nil {
@@ -135,7 +135,9 @@ Please take a look at the usage below to customize the serving parameters`,
if err := service.StartPortableMode(portableSFTPDPort, portableSSHCommands, portableAdvertiseService,
portableAdvertiseCredentials); err == nil {
service.Wait()
os.Exit(0)
}
os.Exit(1)
},
}
)

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
@@ -21,6 +22,7 @@ var (
err := s.Reload()
if err != nil {
fmt.Printf("Error reloading service: %v\r\n", err)
os.Exit(1)
} else {
fmt.Printf("Service reloaded!\r\n")
}

View File

@@ -1,6 +1,8 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/drakkan/sftpgo/service"
@@ -31,7 +33,9 @@ Please take a look at the usage below to customize the startup options`,
}
if err := service.Start(); err == nil {
service.Wait()
os.Exit(0)
}
os.Exit(1)
},
}
)

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
@@ -37,6 +38,7 @@ var (
err := winService.RunService()
if err != nil {
fmt.Printf("Error starting service: %v\r\n", err)
os.Exit(1)
} else {
fmt.Printf("Service started!\r\n")
}

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
@@ -21,6 +22,7 @@ var (
status, err := s.Status()
if err != nil {
fmt.Printf("Error querying service status: %v\r\n", err)
os.Exit(1)
} else {
fmt.Printf("Service status: %#v\r\n", status.String())
}

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
@@ -21,6 +22,7 @@ var (
err := s.Stop()
if err != nil {
fmt.Printf("Error stopping service: %v\r\n", err)
os.Exit(1)
} else {
fmt.Printf("Service stopped!\r\n")
}

View File

@@ -2,6 +2,7 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
@@ -21,6 +22,7 @@ var (
err := s.Uninstall()
if err != nil {
fmt.Printf("Error removing service: %v\r\n", err)
os.Exit(1)
} else {
fmt.Printf("Service uninstalled\r\n")
}