added dev version, changed go namespace, added inline manpage

This commit is contained in:
2022-10-04 15:09:13 +02:00
parent 4596d9d589
commit 43dc4ff031
5 changed files with 78 additions and 26 deletions

View File

@@ -18,19 +18,30 @@
#
# no need to modify anything below
tool = tablizer
version = $(shell egrep "^var Version = " lib/common.go | cut -d'=' -f2 | cut -d'"' -f 2)
version = $(shell egrep "= .v" lib/common.go | cut -d'=' -f2 | cut -d'"' -f 2)
archs = android darwin freebsd linux netbsd openbsd windows
PREFIX = /usr/local
UID = root
GID = 0
PREFIX = /usr/local
UID = root
GID = 0
BRANCH = $(shell git describe --all | cut -d/ -f2)
COMMIT = $(shell git rev-parse --short=8 HEAD)
BUILD = $(shell date +%Y.%m.%d.%H%M%S)
VERSION:= $(if $(filter $(BRANCH), development),$(version)-$(BRANCH)-$(COMMIT)-$(BUILD))
all: buildlocal $(tool).1
all: $(tool).1 cmd/$(tool).go buildlocal
%.1: %.pod
pod2man -c "User Commands" -r 1 -s 1 $*.pod > $*.1
cmd/%.go: %.pod
echo "package cmd" > cmd/$*.go
echo "var manpage = \`" >> cmd/$*.go
pod2text $*.pod >> cmd/$*.go
echo "\`" >> cmd/$*.go
buildlocal:
go build
go build -ldflags "-X 'github.com/tlinden/tablizer/lib.VERSION=$(VERSION)'"
release:
./mkrel.sh $(tool) $(version)
@@ -42,7 +53,7 @@ install: buildlocal
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/
clean:
rm -rf $(tool) $(tool).1 releases
rm -rf $(tool) $(tool).1 cmd/$(tool).go releases
test:
go test -v ./...

View File

@@ -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,
})
}

2
go.mod
View File

@@ -1,4 +1,4 @@
module daemon.de/tablizer
module github.com/tlinden/tablizer
go 1.18

View File

@@ -17,19 +17,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package lib
// command line flags
var Debug bool
var XtendedOut bool
var NoNumbering bool
var ShowVersion bool
var Columns string
var UseColumns []int
var Separator string
var OutflagExtended bool
var OutflagMarkdown bool
var OutflagOrgtable bool
var OutflagShell bool
var OutputMode string
var (
// command line flags
Debug bool
XtendedOut bool
NoNumbering bool
ShowVersion bool
Columns string
UseColumns []int
Separator string
OutflagExtended bool
OutflagMarkdown bool
OutflagOrgtable bool
OutflagShell bool
OutputMode string
var Version = "v1.0.3"
var validOutputmodes = "(orgtbl|markdown|extended|ascii)"
// used for validation
validOutputmodes = "(orgtbl|markdown|extended|ascii)"
// main program version
Version = "v1.0.3"
// generated version string, used by -v contains lib.Version on
// main branch, and lib.Version-$branch-$lastcommit-$date on
// development branch
VERSION string
)

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"daemon.de/tablizer/cmd"
"github.com/tlinden/tablizer/cmd"
)
func main() {