Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
92bd09a2c6 | |||
68b03407e7 | |||
e2da267c47 | |||
70a052d29c |
39
.drone.yml
39
.drone.yml
@ -10,17 +10,30 @@ 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
|
||||
- name: package
|
||||
image: tystuyfzand/fpm
|
||||
commands:
|
||||
- chmod +x scripts/build-package.sh
|
||||
- ARCH=i386 scripts/build-package.sh
|
||||
- ARCH=amd64 scripts/build-package.sh
|
||||
- ARCH=armv7 scripts/build-package.sh
|
||||
- ARCH=arm64 scripts/build-package.sh
|
||||
volumes:
|
||||
- name: build
|
||||
path: /build
|
||||
when:
|
||||
event: tag
|
||||
- name: release
|
||||
image: plugins/gitea-release
|
||||
volumes:
|
||||
@ -29,11 +42,19 @@ steps:
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
gitea_server: https://git.meow.tf
|
||||
base_url: https://git.meow.tf
|
||||
title: release
|
||||
files:
|
||||
- /build/pastee_*
|
||||
checksum:
|
||||
- md5
|
||||
- sha1
|
||||
- sha256
|
||||
environment:
|
||||
PLUGIN_API_KEY:
|
||||
from_secret: gitea_token
|
||||
when:
|
||||
event: tag
|
||||
volumes:
|
||||
- name: build
|
||||
temp: {}
|
@ -1,72 +1,66 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
Key = ""
|
||||
"fmt"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "pastee",
|
||||
Short: "A quick and easy to use Command-Line Paste Interface",
|
||||
Long: `Fast, ad-free, secure, and feature filled! Submit pastes to Paste.ee from any operating system, anywhere!`,
|
||||
Args: cobra.ArbitraryArgs,
|
||||
Run: uploadCommandHandler,
|
||||
Use: "pastee",
|
||||
Short: "A quick and easy to use Command-Line Paste Interface",
|
||||
Long: `Fast, ad-free, secure, and feature filled! Submit pastes to Paste.ee from any operating system, anywhere!`,
|
||||
Args: cobra.ArbitraryArgs,
|
||||
Run: uploadCommandHandler,
|
||||
}
|
||||
|
||||
var (
|
||||
cfgFile string
|
||||
cfgFile string
|
||||
Key = ""
|
||||
)
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
rootCmd.PersistentFlags().BoolP("encrypt", "e", true, "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.SetDefault("apiKey", Key)
|
||||
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("encrypt", rootCmd.PersistentFlags().Lookup("encrypt"))
|
||||
viper.SetDefault("apiKey", Key)
|
||||
|
||||
rootCmd.AddCommand(loginCmd)
|
||||
rootCmd.AddCommand(loginCmd)
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
if cfgFile != "" {
|
||||
// Use config file from the flag.
|
||||
viper.SetConfigFile(cfgFile)
|
||||
} else {
|
||||
home, err := homedir.Dir()
|
||||
cobra.CheckErr(err)
|
||||
if cfgFile != "" {
|
||||
// Use config file from the flag.
|
||||
viper.SetConfigFile(cfgFile)
|
||||
} else {
|
||||
home, err := homedir.Dir()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
viper.SetConfigName(".pastee")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(home)
|
||||
viper.SetConfigName(".pastee")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath(home)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
|
||||
} else {
|
||||
fmt.Println("Error: Configuration file was unable to be read -", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Error: Configuration file was unable to be read -", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viper.AutomaticEnv()
|
||||
viper.AutomaticEnv()
|
||||
}
|
@ -1,64 +1,77 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"paste.ee/go"
|
||||
"path"
|
||||
"errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"paste.ee/go"
|
||||
"path"
|
||||
)
|
||||
|
||||
// uploadCommandHandler handles the root command from Cobra
|
||||
// The program takes two inputs, an arg list (files), or stdin.
|
||||
// If args is empty, stdin will be used.
|
||||
func uploadCommandHandler(cmd *cobra.Command, args []string) {
|
||||
client := pastee.New(viper.GetString("apiKey"))
|
||||
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)))
|
||||
if len(args) > 0 && args[0] != "-" {
|
||||
paste.Sections = make([]*pastee.Section, int(math.Min(float64(len(args)), 10)))
|
||||
|
||||
// File list
|
||||
for i, filePath := range args {
|
||||
if i >= 10 {
|
||||
break
|
||||
}
|
||||
// File list
|
||||
for i, filePath := range args {
|
||||
if i >= 10 {
|
||||
break
|
||||
}
|
||||
|
||||
bytes, err := ioutil.ReadFile(filePath)
|
||||
bytes, err := ioutil.ReadFile(filePath)
|
||||
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Unable to read file:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Unable to read file:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
paste.Sections[i] = &pastee.Section{
|
||||
Name: path.Base(filePath),
|
||||
Contents: string(bytes),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Stdin
|
||||
stdinContents, err := ioutil.ReadAll(os.Stdin)
|
||||
paste.Sections[i] = &pastee.Section{
|
||||
Name: path.Base(filePath),
|
||||
Contents: string(bytes),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Stdin
|
||||
stdinContents, err := ioutil.ReadAll(os.Stdin)
|
||||
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error reading from stdin:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error reading from stdin:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
paste.Sections = []*pastee.Section{
|
||||
{Contents: string(stdinContents)},
|
||||
}
|
||||
}
|
||||
paste.Sections = []*pastee.Section{
|
||||
{Contents: string(stdinContents)},
|
||||
}
|
||||
}
|
||||
|
||||
res, err := client.Submit(paste)
|
||||
res, err := client.Submit(paste)
|
||||
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Unable to upload paste:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err != nil || res.Link == "" {
|
||||
if err == nil {
|
||||
err = errors.New("unknown error")
|
||||
}
|
||||
|
||||
cmd.Println(res.Link)
|
||||
cmd.PrintErrln("Unable to upload paste:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
link := res.Link
|
||||
|
||||
if res.Key != "" {
|
||||
link += "#" + res.Key
|
||||
}
|
||||
|
||||
cmd.Println(link)
|
||||
}
|
13
scripts/build-package.sh
Normal file
13
scripts/build-package.sh
Normal file
@ -0,0 +1,13 @@
|
||||
fpm -s dir -t deb -p /build/pastee_${DRONE_TAG}_${ARCH}.deb \
|
||||
-n ow-api -v $DRONE_TAG -a $ARCH \
|
||||
--deb-priority optional --force \
|
||||
--deb-compression bzip2 \
|
||||
--description "Paste.ee CLI Tool" \
|
||||
-m "Paste.ee <admin@paste.ee>" --vendor "Paste.ee" \
|
||||
-a $ARCH /build/pastee_linux_${ARCH}=/usr/bin/pastee
|
||||
|
||||
fpm -s dir -t rpm -p /build/pastee_${DRONE_TAG}_${ARCH}.rpm \
|
||||
-n ow-api -v $DRONE_TAG -a $ARCH \
|
||||
--description "Paste.ee CLI Tool" \
|
||||
-m "Paste.ee <admin@paste.ee>" --vendor "Paste.ee" \
|
||||
-a $ARCH /build/pastee_linux_${ARCH}=/usr/bin/pastee
|
Reference in New Issue
Block a user