Skip to content

Commit

Permalink
throw errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TanmayPatil105 committed Sep 18, 2023
1 parent e12a97c commit 8631889
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,19 @@ func ReadAll(argLength int, Args []string) {
func WriteAll(argLength int, Args []string) {
text, err := clipboard.ReadAll()
if err != nil {
fmt.Println("Unable to read clipboard contents")
ThrowError(err)
}

for i := 2; i <= argLength; i++ {
file, err := os.Create(Args[i])
if err != nil {
fmt.Println("Failed to create file:", err)
continue
ThrowError(err)
}
defer file.Close()

_, err = file.WriteString(text)
if err != nil {
fmt.Println("Failed to write to file:", err)
continue
ThrowError(err)
}
}
}
Expand All @@ -97,16 +95,15 @@ func main() {

argLength := len(os.Args[1:])

if *write {
WriteAll(argLength, os.Args)
return
}

if argLength < 1 {
fmt.Printf("gclip : %vNot enough arguments%v\n", RedText, NormalText)
os.Exit(1)
}

ReadAll(argLength, os.Args)
if *write {
WriteAll(argLength, os.Args)
return
}

ReadAll(argLength, os.Args)
}

0 comments on commit 8631889

Please sign in to comment.