// 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 ", // 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) } }