rpaste
rpaste
This commit is contained in:
parent
3ba11c2273
commit
afef86d72e
7
go.mod
Normal file
7
go.mod
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module github.com/rocky-linux/rpaste
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
|
gopkg.in/ini.v1 v1.66.2
|
||||||
|
)
|
14
go.sum
Normal file
14
go.sum
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
|
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||||
|
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
|
||||||
|
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
2
modules/paste/ixio.go
Normal file
2
modules/paste/ixio.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// support for ix.io
|
||||||
|
package paste
|
9
modules/paste/method.go
Normal file
9
modules/paste/method.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package paste
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var PasteMethod = []*cli.Command{
|
||||||
|
|
||||||
|
}
|
2
modules/paste/rpaste.go
Normal file
2
modules/paste/rpaste.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// support for rpaste (bpaste)
|
||||||
|
package paste
|
31
modules/setting/setting.go
Normal file
31
modules/setting/setting.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// rpaste settings
|
||||||
|
//
|
||||||
|
// This part of the setting package sets default var types and will set other
|
||||||
|
// important var information, or even load configuration files. Majority of the
|
||||||
|
// needed defaults are not set here. They are set in the main package.
|
||||||
|
package setting
|
||||||
|
|
||||||
|
import (
|
||||||
|
// ini "gopkg.in/ini.v1"
|
||||||
|
_ "github.com/rocky-linux/rpaste/modules/utility"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
AppName string
|
||||||
|
AppBuiltWith string
|
||||||
|
AppConf string
|
||||||
|
AppVer string
|
||||||
|
LexerType string
|
||||||
|
LifeTime string
|
||||||
|
PasteBinService string
|
||||||
|
SysInfo bool
|
||||||
|
)
|
||||||
|
|
||||||
|
// todo: put in support to find conf file in order:
|
||||||
|
// -> user's home ~/.rpaste
|
||||||
|
// -> /etc/rpaste/rpaste.conf
|
||||||
|
// -> or ignore everything and use custom provided
|
||||||
|
|
||||||
|
//func init() {
|
||||||
|
// var err error
|
||||||
|
//}
|
21
modules/setting/usage.go
Normal file
21
modules/setting/usage.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package setting
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
colorGreen = "\033[01;32m"
|
||||||
|
colorReset = "\033[0m"
|
||||||
|
HelpTemplate = "\033[01;32m{{.Name}}\033[0m: {{.Usage}}\n\n" +
|
||||||
|
"{{.Name}} [options] [filepath]\n" +
|
||||||
|
"command | {{.Name}} [options]\n\n" +
|
||||||
|
"Options:\n" +
|
||||||
|
"{{range .VisibleFlags}}{{.}}\n" +
|
||||||
|
"{{end}}"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VersionTemplate(c *cli.Context) {
|
||||||
|
fmt.Printf("%s%s%s version %s\n\n%s\n", colorGreen, c.App.Name, colorReset, c.App.Version, c.App.UsageText)
|
||||||
|
}
|
38
modules/utility/file.go
Normal file
38
modules/utility/file.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// file utility area
|
||||||
|
//
|
||||||
|
// This part of the utility package is primarily for file or path checking.
|
||||||
|
package utility
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
_ "path"
|
||||||
|
_ "path/filepath"
|
||||||
|
_ "strings"
|
||||||
|
_ "errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check if this is a file
|
||||||
|
func IsFile(filePath string) (bool, error) {
|
||||||
|
f, err := os.Stat(filePath)
|
||||||
|
if err == nil {
|
||||||
|
return !f.IsDir(), nil
|
||||||
|
}
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this even exists
|
||||||
|
func IsExist(path string) (bool, error) {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err == nil || os.IsExist(err) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: add string checking, we can't paste binary
|
125
rpaste.go
Normal file
125
rpaste.go
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
// Copyright 2022 The rpaste Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by an MIT-style license that can be
|
||||||
|
// found in the LICENSE file of this git repository or release archive.
|
||||||
|
package main
|
||||||
|
|
||||||
|
// All Imports
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"github.com/rocky-linux/rpaste/modules/setting"
|
||||||
|
_ "github.com/rocky-linux/rpaste/modules/paste"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sane defaults and basic info
|
||||||
|
var (
|
||||||
|
AppName = "rpaste"
|
||||||
|
Version = "0.2.0"
|
||||||
|
DefaultConf = "/etc/rpaste/rpaste.conf"
|
||||||
|
DefaultLexer = "text"
|
||||||
|
DefaultLifeTime = "1hour"
|
||||||
|
DefaultPasteBin = "rpaste"
|
||||||
|
DefaultSysInfo = false
|
||||||
|
ShortOption = true
|
||||||
|
)
|
||||||
|
|
||||||
|
// Initialize default settings
|
||||||
|
func init() {
|
||||||
|
setting.AppName = AppName
|
||||||
|
setting.AppVer = Version
|
||||||
|
setting.AppConf = DefaultConf
|
||||||
|
setting.LexerType = DefaultLexer
|
||||||
|
setting.LifeTime = DefaultLifeTime
|
||||||
|
setting.PasteBinService = DefaultPasteBin
|
||||||
|
setting.SysInfo = DefaultSysInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := &cli.App{
|
||||||
|
Name: AppName,
|
||||||
|
Usage: "Paste utility originally made for the Rocky paste service",
|
||||||
|
Version: Version,
|
||||||
|
// short options should be on
|
||||||
|
UseShortOptionHandling: ShortOption,
|
||||||
|
Compiled: time.Now(),
|
||||||
|
// Explicitly setting these
|
||||||
|
Reader: os.Stdin,
|
||||||
|
Writer: os.Stdout,
|
||||||
|
ErrWriter: os.Stderr,
|
||||||
|
Copyright: "2022 (c) Louis Abel <label@rockylinux.org>",
|
||||||
|
// Usage text at the bottom to keep the editor from putting me on the wrong
|
||||||
|
// column. Additional options should be above these comments.
|
||||||
|
UsageText: `Paste utility used primarily for the Rocky Linux pastebin service.
|
||||||
|
It can collect system information and forward it to a pastebin or simply
|
||||||
|
send regular text files. This utility is primarily used for asking for
|
||||||
|
assistance in the Rocky Linux support venue.`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shorten the help/usage area
|
||||||
|
cli.AppHelpTemplate = setting.HelpTemplate
|
||||||
|
cli.VersionPrinter = setting.VersionTemplate
|
||||||
|
|
||||||
|
defaultFlags := []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "life",
|
||||||
|
Aliases: []string{"x"},
|
||||||
|
Value: setting.LifeTime,
|
||||||
|
Usage: "Sets the syntax highlighting",
|
||||||
|
DefaultText: "1hour",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "type",
|
||||||
|
Aliases: []string{"t"},
|
||||||
|
Value: setting.LexerType,
|
||||||
|
Usage: "Sets the syntax highlighting",
|
||||||
|
DefaultText: "text",
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "sysinfo",
|
||||||
|
Aliases: []string{"s"},
|
||||||
|
Value: setting.SysInfo,
|
||||||
|
Usage: "Collects general system information (disables stdin and file input)",
|
||||||
|
Required: false,
|
||||||
|
},
|
||||||
|
// &cli.StringFlag{
|
||||||
|
// Name: "pastebin",
|
||||||
|
// Aliases: []string{"p"},
|
||||||
|
// Value: setting.PasteBinService,
|
||||||
|
// Usage: "Decides what pastebin to use",
|
||||||
|
// },
|
||||||
|
}
|
||||||
|
|
||||||
|
// append the default flags to both the main and paste method
|
||||||
|
app.Flags = append(app.Flags, paste.PasteMethod.Flags...)
|
||||||
|
app.Flags = append(app.Flags, defaultFlags...)
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
//app.Before = establishConfExistence
|
||||||
|
app.Action = paste.PasteMethod.Action
|
||||||
|
|
||||||
|
app.Commands = []*cli.Command {
|
||||||
|
paste.PasteMethod,
|
||||||
|
}
|
||||||
|
|
||||||
|
// below is an example to make sure this works
|
||||||
|
//app.Commands = []*cli.Command {
|
||||||
|
// {
|
||||||
|
// Name: "test",
|
||||||
|
// Aliases: []string{"t"},
|
||||||
|
// Usage: "testing",
|
||||||
|
// Action: func(c *cli.Context) error {
|
||||||
|
// fmt.Println("testing: ", c.String("type"))
|
||||||
|
// return nil
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
//}
|
||||||
|
|
||||||
|
err := app.Run(os.Args)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user