Skip to content

Commit

Permalink
feat: added version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ngyewch committed Nov 29, 2024
1 parent 87d9c8c commit b936809
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,55 @@ package main

import (
"encoding/json"
"fmt"
"github.com/ngyewch/mdbook-asciidoc/renderer"
"github.com/ngyewch/mdbook-plugin"
"github.com/urfave/cli/v2"
"log"
"os"
"strconv"
"strings"
"time"
)

var (
app = &cli.App{
Name: "mdbook-asciidoc",
Usage: "mdbook-asciidoc",
Action: doMain,
}
version string
commit string
commitTimestamp string
)

func main() {
app := &cli.App{
Name: "mdbook-asciidoc",
Usage: "mdbook-asciidoc",
Version: version,
Action: doMain,
}

cli.VersionPrinter = func(cCtx *cli.Context) {
var parts []string
if version != "" {
parts = append(parts, fmt.Sprintf("version=%s", version))
}
if commit != "" {
parts = append(parts, fmt.Sprintf("commit=%s", commit))
}
if commitTimestamp != "" {
formattedCommitTimestamp := func(commitTimestamp string) string {
epochSeconds, err := strconv.ParseInt(commitTimestamp, 10, 64)
if err != nil {
return ""
}
t := time.Unix(epochSeconds, 0)
return t.Format(time.RFC3339)
}(commitTimestamp)
if formattedCommitTimestamp != "" {
parts = append(parts, fmt.Sprintf("commitTimestamp=%s", formattedCommitTimestamp))
}
}
fmt.Println(strings.Join(parts, " "))
}

err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit b936809

Please sign in to comment.