Resolve key issue
This commit is contained in:
parent
e2da267c47
commit
68b03407e7
16
.drone.yml
16
.drone.yml
@ -10,14 +10,14 @@ steps:
|
||||
path: /build
|
||||
commands:
|
||||
- mkdir -p /build
|
||||
- GOOS=linux GOARCH=386 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_linux_i386
|
||||
- GOOS=linux GOARCH=amd64 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_linux_amd64
|
||||
- GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_linux_armv7
|
||||
- GOOS=linux GOARCH=arm64 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_linux_arm64
|
||||
- GOOS=windows GOARCH=386 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_windows_i386.exe
|
||||
- GOOS=windows GOARCH=amd64 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_windows_amd64.exe
|
||||
- GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_macos_arm64
|
||||
- GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'cmd.Key=$API_KEY'" -o /build/pastee_macos_amd64
|
||||
- GOOS=linux GOARCH=386 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_linux_i386
|
||||
- GOOS=linux GOARCH=amd64 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_linux_amd64
|
||||
- GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_linux_armv7
|
||||
- GOOS=linux GOARCH=arm64 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_linux_arm64
|
||||
- GOOS=windows GOARCH=386 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_windows_i386.exe
|
||||
- GOOS=windows GOARCH=amd64 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_windows_amd64.exe
|
||||
- GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_macos_arm64
|
||||
- GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'paste.ee/cli/cmd.Key=$API_KEY'" -o /build/pastee_macos_amd64
|
||||
environment:
|
||||
API_KEY:
|
||||
from_secret: api_key
|
||||
|
@ -8,10 +8,6 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
Key = ""
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "pastee",
|
||||
Short: "A quick and easy to use Command-Line Paste Interface",
|
||||
@ -22,6 +18,7 @@ var rootCmd = &cobra.Command{
|
||||
|
||||
var (
|
||||
cfgFile string
|
||||
Key = ""
|
||||
)
|
||||
|
||||
func Execute() {
|
||||
@ -34,13 +31,10 @@ func Execute() {
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
rootCmd.PersistentFlags().BoolP("encrypt", "e", true, "Encrypt uploaded contents")
|
||||
rootCmd.PersistentFlags().BoolP("encrypt", "e", false, "Encrypt uploaded contents")
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
|
||||
rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
|
||||
viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))
|
||||
viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))
|
||||
viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
|
||||
viper.SetDefault("license", "apache")
|
||||
viper.BindPFlag("encrypt", rootCmd.PersistentFlags().Lookup("encrypt"))
|
||||
viper.SetDefault("apiKey", Key)
|
||||
|
||||
rootCmd.AddCommand(loginCmd)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"io/ioutil"
|
||||
@ -16,7 +17,9 @@ import (
|
||||
func uploadCommandHandler(cmd *cobra.Command, args []string) {
|
||||
client := pastee.New(viper.GetString("apiKey"))
|
||||
|
||||
paste := &pastee.Paste{}
|
||||
paste := &pastee.Paste{
|
||||
Encrypted: viper.GetBool("encrypt"),
|
||||
}
|
||||
|
||||
if len(args) > 0 && args[0] != "-" {
|
||||
paste.Sections = make([]*pastee.Section, int(math.Min(float64(len(args)), 10)))
|
||||
@ -55,10 +58,20 @@ func uploadCommandHandler(cmd *cobra.Command, args []string) {
|
||||
|
||||
res, err := client.Submit(paste)
|
||||
|
||||
if err != nil {
|
||||
if err != nil || res.Link == "" {
|
||||
if err == nil {
|
||||
err = errors.New("unknown error")
|
||||
}
|
||||
|
||||
cmd.PrintErrln("Unable to upload paste:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cmd.Println(res.Link)
|
||||
link := res.Link
|
||||
|
||||
if res.Key != "" {
|
||||
link += "#" + res.Key
|
||||
}
|
||||
|
||||
cmd.Println(link)
|
||||
}
|
Loading…
Reference in New Issue
Block a user