You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
4.0 KiB

// 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 (
// Sane defaults and basic info
var (
AppName = "rpaste"
Version = "0.3.0"
DefaultConf = "/etc/rpaste/rpaste.conf"
DefaultLexer = "text"
DefaultLifeTime = "1hour"
// This will end up being dynamic in the future
DefaultPasteBin = "rpaste"
DefaultSysInfo = false
DefaultDryMode = false
DefaultBasicDmidecode = false
ShortOption = true
// Initialize default settings
func init() {
setting.AppName = AppName
setting.AppVer = Version
setting.AppConf = DefaultConf
setting.DryMode = DefaultDryMode
setting.LexerType = DefaultLexer
setting.LifeTime = DefaultLifeTime
setting.PasteBinService = DefaultPasteBin
setting.SysInfo = DefaultSysInfo
setting.BasicDmidecode = DefaultBasicDmidecode
// read config?
func main() {
app := &cli.App{
Name: AppName,
Usage: "A 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 <>",
// 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 community support venue. It can also be used on
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.
Commands: []*cli.Command{
// Shorten the help/usage area
cli.AppHelpTemplate = setting.HelpTemplate
cli.VersionPrinter = setting.VersionTemplate
// 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.
defaultFlags := []cli.Flag{
Name: "life",
Aliases: []string{"x"},
Value: setting.LifeTime,
Usage: "Sets the life time of a paste (1hour, 1day, 1week)",
DefaultText: "1hour",
Name: "type",
Aliases: []string{"t"},
Value: setting.LexerType,
Usage: "Sets the syntax highlighting",
DefaultText: "text",
Name: "sysinfo",
Aliases: []string{"s"},
Value: setting.SysInfo,
Usage: "Collects general system information (disables stdin and file input)",
Required: false,
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,
Name: "pastebin",
Aliases: []string{"p"},
Value: setting.PasteBinService,
Usage: "Sets the paste bin service to send to. Current supported: rpaste, fpaste",
Required: false,
// 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 = utility.SetPasteOnOS
app.Action = paste.PasteMethod.Action
// Verify reader is set
if app.Reader != os.Stdin {
log.Println("stdin not set")
err := app.Run(os.Args)
if err != nil {