diff --git a/.gitignore b/.gitignore index affd76ad..0015aba9 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ yum-install.sh goreleaser-test.sh /.vscode /completions +/manpages diff --git a/.goreleaser.yml b/.goreleaser.yml index 4b74b841..a66740b6 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,6 +2,7 @@ before: hooks: - go mod tidy - ./.completions.sh + - ./.manpages.sh builds: - builder: prebuilt @@ -34,6 +35,7 @@ archives: - LICENSE - CHANGELOG.md - completions/* + - manpages/* checksum: name_template: 'checksums.txt' @@ -67,6 +69,7 @@ brews: bash_completion.install "completions/sq.bash" => "sq" zsh_completion.install "completions/sq.zsh" => "_sq" fish_completion.install "completions/sq.fish" + man1.install "manpages/sq.1.gz" test: | system "#{bin}/sq --version" @@ -107,12 +110,15 @@ nfpms: dst: /usr/share/zsh/vendor-completions/_sq file_info: mode: 0644 + - src: ./manpages/sq.1.gz + dst: /usr/share/man/man1/sq.1.gz + file_info: + mode: 0644 furies: # Upload deb and rpm to fury.io. Requires that envar $FURY_TOKEN be set. - account: neilotoole -# .goreleaser.yaml aurs: - # The package name. @@ -226,14 +232,15 @@ aurs: mkdir -p "${pkgdir}/usr/share/zsh/site-functions/" mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/" - #install -Dm644 "./completions/sq.bash" "${pkgdir}/usr/share/bash-completion/completions/sq" - #install -Dm644 "./completions/sq.zsh" "${pkgdir}/usr/share/zsh/site-functions/_sq" - #install -Dm644 "./completions/sq.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/sq.fish" + install -Dm644 "./completions/sq.bash" "${pkgdir}/usr/share/bash-completion/completions/sq" + install -Dm644 "./completions/sq.zsh" "${pkgdir}/usr/share/zsh/site-functions/_sq" + install -Dm644 "./completions/sq.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/sq.fish" # docs mkdir -p "${pkgdir}/usr/share/doc/sq" install -Dm644 "./README.md" "${pkgdir}/usr/share/doc/sq/README.md" - #install -Dm644 "./manpages/mybin.1.gz" "${pkgdir}/usr/share/man/man1/mybin.1.gz" + mkdir -p "${pkgdir}/usr/share/man/man1" + install -Dm644 "./manpages/sq.1.gz" "${pkgdir}/usr/share/man/man1/sq.1.gz" # Git author used to commit to the repository. # Defaults are shown below. diff --git a/.manpages.sh b/.manpages.sh new file mode 100755 index 00000000..61515111 --- /dev/null +++ b/.manpages.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# This script generates man pages. +set -e +rm -rf manpages +mkdir manpages +go run . man | gzip -c -9 >manpages/sq.1.gz diff --git a/CHANGELOG.md b/CHANGELOG.md index 58919548..0844dfec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v0.20.0] - 2022-12-29 + +### Added + +- `sq` now generates manpages (and installs them). + ## [v0.19.0] - 2022-12-29 ### Added @@ -86,6 +92,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#89]: Bug with SQL generated for joins. +[v0.19.0]: https://github.com/neilotoole/sq/compare/v0.19.0...v0.20.0 [v0.19.0]: https://github.com/neilotoole/sq/compare/v0.18.2...v0.19.0 [v0.18.2]: https://github.com/neilotoole/sq/compare/v0.18.0...v0.18.2 [v0.18.0]: https://github.com/neilotoole/sq/compare/v0.17.0...v0.18.0 diff --git a/cli/cli.go b/cli/cli.go index 57bde7b7..dad9044c 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -190,6 +190,7 @@ func newCommandTree(rc *RunContext) (rootCmd *cobra.Command) { defer cobraMu.Unlock() rootCmd = newRootCmd() + rootCmd.DisableAutoGenTag = true rootCmd.SetOut(rc.Out) rootCmd.SetErr(rc.ErrOut) rootCmd.Flags().SortFlags = false @@ -234,6 +235,7 @@ func newCommandTree(rc *RunContext) (rootCmd *cobra.Command) { addCmd(rc, tblCmd, newTblDropCmd()) addCmd(rc, rootCmd, newCompletionCmd()) + addCmd(rc, rootCmd, newManCmd()) return rootCmd } @@ -259,6 +261,8 @@ func addCmd(rc *RunContext, parentCmd, cmd *cobra.Command) *cobra.Command { cmd.Flags().Bool(flagHelp, false, "help for "+cmd.Name()) } + cmd.DisableAutoGenTag = true + cmd.PreRunE = func(cmd *cobra.Command, args []string) error { rc.Cmd = cmd rc.Args = args diff --git a/cli/cmd_man.go b/cli/cmd_man.go new file mode 100644 index 00000000..a4c2de7c --- /dev/null +++ b/cli/cmd_man.go @@ -0,0 +1,34 @@ +package cli + +import ( + "fmt" + + mcobra "github.com/muesli/mango-cobra" + "github.com/muesli/roff" + "github.com/spf13/cobra" +) + +func newManCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "man", + Short: "Generate man pages", + SilenceUsage: true, + DisableFlagsInUseLine: true, + Hidden: true, + Args: cobra.NoArgs, + RunE: execGenerateMan, + } + + return cmd +} + +func execGenerateMan(cmd *cobra.Command, args []string) error { + rc := RunContextFrom(cmd.Context()) + manPage, err := mcobra.NewManPage(1, cmd.Root()) + if err != nil { + return err + } + + _, err = fmt.Fprint(rc.Out, manPage.Build(roff.NewDocument())) + return err +} diff --git a/go.mod b/go.mod index 1426146b..caad57e1 100644 --- a/go.mod +++ b/go.mod @@ -43,11 +43,17 @@ require ( replace github.com/docker/docker => github.com/docker/docker v20.10.3-0.20221013203545-33ab36d6b304+incompatible require ( - github.com/dolmen-go/contextio v0.0.0-20220904134943-e50796217f5f // indirect + github.com/muesli/mango-cobra v1.2.0 + github.com/muesli/roff v0.1.0 +) + +require ( github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/klauspost/compress v1.11.13 // indirect github.com/moby/patternmatcher v0.5.0 // indirect github.com/moby/sys/sequential v0.5.0 // indirect + github.com/muesli/mango v0.1.0 // indirect + github.com/muesli/mango-pflag v0.1.0 // indirect github.com/rivo/uniseg v0.4.3 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect golang.org/x/crypto v0.4.0 // indirect diff --git a/go.sum b/go.sum index d1bb8daa..d81449dc 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,6 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dolmen-go/contextio v0.0.0-20220904134943-e50796217f5f h1:ORMUh1YgoSZoBGaO/i1rGDNeEavjhSnDBQTH9OG8H+o= -github.com/dolmen-go/contextio v0.0.0-20220904134943-e50796217f5f/go.mod h1:cxc20xI7fOgsFHWgt+PenlDDnMcrvh7Ocuj5hEFIdEk= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= @@ -194,6 +192,14 @@ github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= +github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI= +github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= +github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg= +github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA= +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/neilotoole/errgroup v0.1.5 h1:DxEGoIfFm5ooGicidR+okiHjoOaGRKFaSxDPVZuuu2I= github.com/neilotoole/errgroup v0.1.5/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C2S41udRnToE= github.com/neilotoole/lg v0.3.0 h1:2/IESY8l903AeK9nvH3AWVI/p8up+8wmKWIuts7PpxY=