Skip to content

Commit

Permalink
feat: add manpages
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 13, 2022
1 parent 0649d41 commit 0e3ca73
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ go 1.19

require (
github.com/aymanbagabas/go-osc52 v1.2.0
github.com/muesli/mango v0.2.0
github.com/muesli/mango-pflag v0.1.0
github.com/muesli/roff v0.1.0
github.com/spf13/pflag v1.0.5
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
github.com/aymanbagabas/go-osc52 v1.2.0 h1:y4lxy5qmZh7hsLj9EOgMCk2qsPE+e5bOQ8EiLy77b3E=
github.com/aymanbagabas/go-osc52 v1.2.0/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
github.com/muesli/mango v0.2.0 h1:iNNc0c5VLQ6fsMgAqGQofByNUBH2Q2nEbD6TaI+5yyQ=
github.com/muesli/mango v0.2.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"strings"

"github.com/aymanbagabas/go-osc52"
"github.com/muesli/mango"
mpflag "github.com/muesli/mango-pflag"
"github.com/muesli/roff"
"github.com/spf13/pflag"
)

Expand All @@ -23,6 +26,7 @@ var (
version = pflag.BoolP("version", "v", false, "Print version and exit.")
help = pflag.BoolP("help", "h", false, "Print help and exit.")
debug = pflag.BoolP("debug", "d", false, "Print debug information.")
man = pflag.Bool("man", false, "Generate man pages.")
)

func usage(isError bool) {
Expand All @@ -47,6 +51,8 @@ func main() {
usage(true)
}
pflag.Parse()
pflag.Lookup("debug").Hidden = true
pflag.Lookup("man").Hidden = true

if *version {
fmt.Printf("%s version %s (%s)", ProjectName, Version, CommitSHA)
Expand All @@ -58,6 +64,17 @@ func main() {
os.Exit(0)
}

if *man {
manPage := mango.NewManPage(1, ProjectName, "Copy content to the system clipboard from any supported terminal using ANSI OSC 52 sequence.").
WithLongDescription(ProjectName+" a utility that copies text to your clipboard from anywhere using ANSI OSC52 sequence.").
WithSection("Copyright", "(C) 2022 Ayman Bagabas.\n"+
"Released under MIT license.")

pflag.VisitAll(mpflag.PFlagVisitor(manPage))
fmt.Println(manPage.Build(roff.NewDocument()))
os.Exit(0)
}

var str string
args := pflag.Args()
// read from stdin if no arguments are provided and we are not clearing the
Expand Down

0 comments on commit 0e3ca73

Please sign in to comment.