commit d503eaaac558a8f4b185595c1e357b0456ea80bc Author: webb Date: Thu Sep 3 17:10:07 2020 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c04fa2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +interrupt +main diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..c0cbcca --- /dev/null +++ b/COPYING @@ -0,0 +1,11 @@ +Copyright 2020 webb + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/main.go b/main.go new file mode 100644 index 0000000..3e73c5a --- /dev/null +++ b/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "errors" + "fmt" + "gitea.com/webb/teal" + "os" +) + +var itCl = teal.Client{ + UserAgent: "interrupt v0.0.0", +} + +func printUsage() { + fmt.Println("Usage \n") +} + +func getUploadKey() (string, error) { + PXL_KEY := os.Getenv("PXL_KEY") + if PXL_KEY != "" { + return PXL_KEY, nil + } + + MIRAGE_KEY := os.Getenv("MIRAGE_KEY") + if MIRAGE_KEY != "" { + return MIRAGE_KEY, nil + } + + return "", errors.New("Upload key not set as environment variable!") +} + +func main() { + switch os.Args[1] { + case "upload": + if len(os.Args[2:]) > 1 { + fmt.Println("ERROR: too many arguments!") + os.Exit(1) + } else if len(os.Args[2:]) == 0 { + fmt.Println("Please supply a file to upload.") + os.Exit(1) + } + + uploadHandler(os.Args[1]) + } +} diff --git a/upload.go b/upload.go new file mode 100644 index 0000000..d91ae0a --- /dev/null +++ b/upload.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "io" + "os" +) + +func uploadHandler(a string) { + uploadKey, err := getUploadKey() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + var reader io.Reader + + if os.Args[2] == "-" { + reader = os.Stdin + } else { + reader, err = os.Open(a) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + } + + itCl.UploadKey = uploadKey + + r, err := itCl.UploadFile(reader, a) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + fmt.Println(r) + os.Exit(0) +}