rpaste/rpaste.go

137 lines
4 KiB
Go
Raw Normal View History

2021-12-21 01:06:08 +00:00
// 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 (
2021-12-24 09:01:22 +00:00
"log"
"os"
"time"
"github.com/rocky-linux/rpaste/modules/paste"
"github.com/rocky-linux/rpaste/modules/setting"
"github.com/urfave/cli/v2"
2021-12-21 01:06:08 +00:00
)
// Sane defaults and basic info
var (
2021-12-24 09:01:22 +00:00
AppName = "rpaste"
2024-12-04 02:50:21 +00:00
Version = "0.3.3"
2021-12-24 09:01:22 +00:00
DefaultConf = "/etc/rpaste/rpaste.conf"
DefaultLexer = "text"
2023-04-06 17:55:24 +00:00
DefaultLifeTime = "1day"
2021-12-28 04:27:10 +00:00
// This will end up being dynamic in the future
2022-01-01 23:41:59 +00:00
DefaultPasteBin = "rpaste"
DefaultSysInfo = false
DefaultDryMode = false
DefaultBasicDmidecode = false
ShortOption = true
2021-12-21 01:06:08 +00:00
)
// Initialize default settings
func init() {
2021-12-24 09:01:22 +00:00
setting.AppName = AppName
setting.AppVer = Version
setting.AppConf = DefaultConf
2022-01-01 23:41:59 +00:00
setting.DryMode = DefaultDryMode
2021-12-24 09:01:22 +00:00
setting.LexerType = DefaultLexer
setting.LifeTime = DefaultLifeTime
setting.PasteBinService = DefaultPasteBin
setting.SysInfo = DefaultSysInfo
2022-01-01 23:41:59 +00:00
setting.BasicDmidecode = DefaultBasicDmidecode
2021-12-29 07:40:36 +00:00
// read config?
2021-12-21 01:06:08 +00:00
}
func main() {
2021-12-24 09:01:22 +00:00
app := &cli.App{
Name: AppName,
2021-12-28 04:27:10 +00:00
Usage: "A paste utility originally made for the Rocky paste service",
2021-12-24 09:01:22 +00:00
Version: Version,
// short options should be on
UseShortOptionHandling: ShortOption,
Compiled: time.Now(),
// Explicitly setting these
Reader: os.Stdin,
Writer: os.Stdout,
ErrWriter: os.Stderr,
2024-12-04 02:50:21 +00:00
Copyright: "2024 (c) Louis Abel <label@rockylinux.org>",
2021-12-24 09:01:22 +00:00
// 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.
2021-12-21 01:06:08 +00:00
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
2021-12-28 04:27:10 +00:00
assistance in the Rocky Linux community support venue. It can also be used on
2021-12-29 07:40:36 +00:00
other systems like Fedora and other Enterprise Linux distributions.
See rpaste(1)`,
// list all commands below - For now it's only the method to paste, which
// isn't callable, it's the default. The flags dictate what happens next.
2021-12-24 09:01:22 +00:00
Commands: []*cli.Command{
paste.PasteMethod,
},
}
2021-12-21 01:06:08 +00:00
2021-12-24 09:01:22 +00:00
// Shorten the help/usage area
cli.AppHelpTemplate = setting.HelpTemplate
cli.VersionPrinter = setting.VersionTemplate
2021-12-21 01:06:08 +00:00
2021-12-29 07:40:36 +00:00
// Supported flags - This controls the life, syntax, or paste bin that it
// the data is sent to. It also allows running a full sysinfo call.
2021-12-24 09:01:22 +00:00
defaultFlags := []cli.Flag{
&cli.StringFlag{
Name: "life",
Aliases: []string{"x"},
Value: setting.LifeTime,
2024-12-04 02:50:21 +00:00
Usage: "Sets the life time of a paste (1h/1hour, 1d/1day, 1w/1week)",
2021-12-24 09:01:22 +00:00
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,
},
2022-01-01 23:41:59 +00:00
&cli.BoolFlag{
Name: "dry",
Aliases: []string{"d"},
Value: setting.DryMode,
Usage: "Turns on dry mode, which doesn't paste the output, but shows the data to stdin",
Required: false,
},
2021-12-29 07:40:36 +00:00
&cli.StringFlag{
Name: "pastebin",
Aliases: []string{"p"},
Value: setting.PasteBinService,
2022-01-02 00:01:50 +00:00
Usage: "Sets the paste bin service to send to. Current supported: rpaste, fpaste",
2021-12-29 07:40:36 +00:00
Required: false,
},
2021-12-24 09:01:22 +00:00
}
2021-12-21 01:06:08 +00:00
2021-12-24 09:01:22 +00:00
// 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...)
2021-12-21 01:06:08 +00:00
2021-12-24 09:01:22 +00:00
// Actions
2021-12-28 04:27:10 +00:00
//app.Before = utility.SetPasteOnOS
2021-12-24 09:01:22 +00:00
app.Action = paste.PasteMethod.Action
2021-12-21 01:06:08 +00:00
2021-12-24 09:01:22 +00:00
// Verify reader is set
if app.Reader != os.Stdin {
log.Println("stdin not set")
}
2021-12-21 01:06:08 +00:00
2021-12-24 09:01:22 +00:00
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
2021-12-21 01:06:08 +00:00
}