mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
added dev version, changed go namespace, added inline manpage
This commit is contained in:
35
cmd/root.go
35
cmd/root.go
@@ -17,19 +17,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"daemon.de/tablizer/lib"
|
||||
"bytes"
|
||||
"github.com/tlinden/tablizer/lib"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
var helpCmd = &cobra.Command{
|
||||
Use: "help",
|
||||
Short: "Show documentation",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
man := exec.Command("less", "-")
|
||||
|
||||
var b bytes.Buffer
|
||||
b.Write([]byte(manpage))
|
||||
|
||||
man.Stdout = os.Stdout
|
||||
man.Stdin = &b
|
||||
man.Stderr = os.Stderr
|
||||
|
||||
err := man.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "tablizer [regex] [file, ...]",
|
||||
Short: "[Re-]tabularize tabular data",
|
||||
Long: `Manipulate tabular output of other programs`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if lib.ShowVersion {
|
||||
fmt.Printf("This is tablizer version %s\n", lib.Version)
|
||||
fmt.Printf("This is tablizer version %s\n", lib.VERSION)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -74,4 +98,11 @@ func init() {
|
||||
|
||||
// same thing but more common, takes precedence over above group
|
||||
rootCmd.PersistentFlags().StringVarP(&lib.OutputMode, "output", "o", "", "Output mode - one of: orgtbl, markdown, extended, shell, ascii(default)")
|
||||
|
||||
rootCmd.AddCommand(helpCmd)
|
||||
|
||||
rootCmd.SetHelpCommand(&cobra.Command{
|
||||
Use: "no-help",
|
||||
Hidden: true,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user