Skip to content

Commit

Permalink
Exit Codes -1 -4
Browse files Browse the repository at this point in the history
  • Loading branch information
iaymerich committed Aug 1, 2018
1 parent 43ef092 commit d35f901
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions jbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"compress/gzip"
"log"
"bufio"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -62,18 +63,18 @@ func main() {
fmt.Println("Generating golang source class")
file, err := generateSource(tempWorkFolder)
if err != nil {
exitWithError(err)
exitWithError(err,-1)
}

destDir := *flagDest
err = os.MkdirAll(destDir, 0755)
if err != nil {
exitWithError(err)
exitWithError(err,-2)
}
sourceFile :=path.Join(destDir, nameSourceFile)
err = rename(file.Name(),sourceFile)
if err != nil {
exitWithError(err)
exitWithError(err,-3)
}
extension := "bin"
if strings.Compare(*flagPlatform,"windows")==0 {
Expand Down Expand Up @@ -253,9 +254,10 @@ func FprintZipData(dest *bytes.Buffer, zipData []byte) {
}

// Prints out the error message and exists with a non-success signal.
func exitWithError(err error) {
func exitWithError(err error,exitCode int) {

fmt.Println(err)
os.Exit(1)
os.Exit(exitCode)
}

func downloadJRE(workDir string){
Expand Down Expand Up @@ -284,7 +286,7 @@ func downloadJRE(workDir string){
}

func DownloadFile(filepath string, url string) error {
fmt.Printf("Downloading %s",url)
fmt.Printf("Downloading %s\n",url)
// Create the file
out, err := os.Create(filepath)
if err != nil {
Expand All @@ -294,6 +296,9 @@ func DownloadFile(filepath string, url string) error {

// Get the data
resp, err := http.Get(url)
if resp.StatusCode == 404 {
exitWithError(errors.New(strings.Replace("URL Repository JRE not found: {url}","{url}",url,-1)),-4)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -353,6 +358,7 @@ func ExtractTarGz(srcTarGzPath string,destination string) {
}
file.Close()
}

func Copy(src, dst string) error {
in, err := os.Open(src)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

// Describe version.
const Version string = "0.0.4"
const Version string = "0.0.5-ALPHA2"

0 comments on commit d35f901

Please sign in to comment.