-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: print version info using
rbmk version
(#40)
Useful to know which version we're using (e.g., in bug reports).
- Loading branch information
1 parent
f35ca36
commit dbde41f
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
# rbmk version - Print Version Information | ||
|
||
## Usage | ||
|
||
``` | ||
rbmk version | ||
``` | ||
|
||
## Description | ||
|
||
Prints on the stdout version information. We add version information | ||
when compiling `rbmk` using the `GNUMakefile`. | ||
|
||
Possible values for the version information are: | ||
|
||
- `dev` if we did not compile using the `GNUMakefile`. | ||
|
||
- `vX.Y.Z` if using `GNUMakefile` to build a specific tag. | ||
|
||
- `vX.Y.Z-<N>-g<SHA>` if using `GNUMakefile` to build | ||
a commit not associated with a tag. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// Package version implements the `rbmk version` command. | ||
package version | ||
|
||
import ( | ||
"context" | ||
_ "embed" | ||
"fmt" | ||
|
||
"github.com/rbmk-project/common/cliutils" | ||
"github.com/rbmk-project/rbmk/internal/markdown" | ||
) | ||
|
||
// Version is the program version. | ||
var Version string = "dev" | ||
|
||
//go:embed README.md | ||
var readme string | ||
|
||
// NewCommand creates the `rbmk version` Command. | ||
func NewCommand() cliutils.Command { | ||
return command{} | ||
} | ||
|
||
type command struct{} | ||
|
||
// Help implements [cliutils.Command]. | ||
func (cmd command) Help(env cliutils.Environment, argv ...string) error { | ||
fmt.Fprintf(env.Stdout(), "%s\n", markdown.MaybeRender(readme)) | ||
return nil | ||
} | ||
|
||
// Main implements [cliutils.Command]. | ||
func (cmd command) Main(ctx context.Context, env cliutils.Environment, argv ...string) error { | ||
// 1. honour requests for printing the help | ||
if cliutils.HelpRequested(argv...) { | ||
return cmd.Help(env, argv...) | ||
} | ||
|
||
// 2. print the version | ||
fmt.Fprintln(env.Stdout(), Version) | ||
return nil | ||
} |