Use return instead of os.exit
This commit is contained in:
30
main.go
30
main.go
@@ -41,33 +41,33 @@ func main() {
|
|||||||
err := clipboard.Init()
|
err := clipboard.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error initializing clipboard: %v", err)
|
Error.Fatalf("Error initializing clipboard: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
envvar, err := godotenv.Parse(strings.NewReader(env))
|
envvar, err := godotenv.Parse(strings.NewReader(env))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error parsing .env file: %v", err)
|
Error.Fatalf("Error parsing .env file: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
username, ok := envvar["GITEA_USER"]
|
username, ok := envvar["GITEA_USER"]
|
||||||
if !ok {
|
if !ok {
|
||||||
Error.Fatalf("GITEA_USER environment variable is required")
|
Error.Fatalf("GITEA_USER environment variable is required")
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
password, ok := envvar["GITEA_PASSWORD"]
|
password, ok := envvar["GITEA_PASSWORD"]
|
||||||
if !ok {
|
if !ok {
|
||||||
Error.Fatalf("GITEA_PASSWORD environment variable is required")
|
Error.Fatalf("GITEA_PASSWORD environment variable is required")
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
url, ok := envvar["GITEA_URL"]
|
url, ok := envvar["GITEA_URL"]
|
||||||
if !ok {
|
if !ok {
|
||||||
Error.Fatalf("GITEA_URL environment variable is required")
|
Error.Fatalf("GITEA_URL environment variable is required")
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if username == "" || password == "" {
|
if username == "" || password == "" {
|
||||||
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")
|
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var name, remote string
|
var name, remote string
|
||||||
@@ -89,13 +89,13 @@ func main() {
|
|||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
Error.Fatalf("Repository name is required")
|
Error.Fatalf("Repository name is required")
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := gitea.NewClient(url)
|
client, err := gitea.NewClient(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error creating client: %v", err)
|
Error.Fatalf("Error creating client: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
client.SetBasicAuth("dave", "D7u@NHh^9d33ue!xVAEu")
|
client.SetBasicAuth("dave", "D7u@NHh^9d33ue!xVAEu")
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error creating repository: %v", err)
|
Error.Fatalf("Error creating repository: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Repository created at:\n%s", repo.CloneURL)
|
log.Printf("Repository created at:\n%s", repo.CloneURL)
|
||||||
clipboard.Write(clipboard.FmtText, []byte(repo.CloneURL))
|
clipboard.Write(clipboard.FmtText, []byte(repo.CloneURL))
|
||||||
@@ -121,7 +121,7 @@ func main() {
|
|||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error getting current working directory: %v", err)
|
Error.Fatalf("Error getting current working directory: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
cwd = path.Clean(cwd)
|
cwd = path.Clean(cwd)
|
||||||
|
|
||||||
@@ -131,13 +131,13 @@ func main() {
|
|||||||
localRepo, err = git.PlainOpen(cwd)
|
localRepo, err = git.PlainOpen(cwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error opening git repository: %v", err)
|
Error.Fatalf("Error opening git repository: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localRepo, err = git.PlainInit(cwd, false)
|
localRepo, err = git.PlainInit(cwd, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error initializing git repository: %v", err)
|
Error.Fatalf("Error initializing git repository: %v", err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_, err = localRepo.Remote(remote)
|
_, err = localRepo.Remote(remote)
|
||||||
@@ -146,11 +146,11 @@ func main() {
|
|||||||
err = localRepo.DeleteRemote(remote)
|
err = localRepo.DeleteRemote(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error deleting remote %s from local repository: %v", remote, err)
|
Error.Fatalf("Error deleting remote %s from local repository: %v", remote, err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Error.Fatalf("Remote %s already exists in local repository", remote)
|
Error.Fatalf("Remote %s already exists in local repository", remote)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error adding remote %s to local repository: %v", remote, err)
|
Error.Fatalf("Error adding remote %s to local repository: %v", remote, err)
|
||||||
os.Exit(1)
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Remote added to local repository")
|
log.Printf("Remote added to local repository")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user