Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
This patch adds a version command to display resticprofile version. If
this command is run with verbose flag, additional such as OS version,
golang version and modules are displayed.

Signed-off-by: Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
  • Loading branch information
Sébastien Gross authored and creativeprojects committed Sep 19, 2020
1 parent 614acc7 commit 06f98e9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ resticprofile flags:
-w, --wait wait at the end until the user presses the enter key

resticprofile own commands:
version display version (run in vebose mode for detailed information)
self-update update resticprofile to latest version (does not update restic)
profiles display profile names from the configuration file
show show all the details of the current profile
Expand Down Expand Up @@ -606,6 +607,14 @@ For that matter I've introduced a parameter in the `global` section called `min-
It compares against `(total - used)` which is probably the best way to know how much memory is available (that is including the memory used for disk buffers/cache).
## Version
The `version` command displays resticprofile version. If run in vebose mode (using `--verbose` flag) additional information such as OS version or golang version or modules are displayed as well.
```
$ resticprofile --verbose version
```
## Generating random keys
resticprofile has a handy tool to generate cryptographically secure random keys encoded in base64. You can simply put this key into a file and use it as a strong key for restic
Expand Down
34 changes: 34 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"runtime"
"runtime/debug"
"sort"
"strconv"
"strings"
Expand All @@ -30,6 +31,12 @@ type ownCommand struct {

var (
ownCommands = []ownCommand{
{
name: "version",
description: "display version (run in vebose mode for detailed information)",
action: displayVersion,
needConfiguration: false,
},
{
name: "self-update",
description: "update resticprofile to latest version (does not update restic)",
Expand Down Expand Up @@ -135,6 +142,33 @@ func displayProfilesCommand(configuration *config.Config, _ commandLineFlags, _
return nil
}

func displayVersion(_ *config.Config, flags commandLineFlags, _ []string) error {
fmt.Printf("resticprofile version %s commit %s.\n", version, commit)

if flags.verbose {
w := tabwriter.NewWriter(os.Stderr, 0, 0, 3, ' ', 0)
_, _ = fmt.Fprintf(w, "\n")
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "home", "https://github.com/creativeprojects/resticprofile")
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "os", runtime.GOOS)
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "arch", runtime.GOARCH)
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "version", version)
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "commit", commit)
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "compiled", date)
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "by", builtBy)
_, _ = fmt.Fprintf(w, "\t%s:\t%s\n", "go version", runtime.Version())
_, _ = fmt.Fprintf(w, "\n")
_, _ = fmt.Fprintf(w, "\t%s:\n", "go modules")
bi, _ := debug.ReadBuildInfo()
for _, dep := range bi.Deps {
_, _ = fmt.Fprintf(w, "\t\t%s\t%s\n", dep.Path, dep.Version)
}
_, _ = fmt.Fprintf(w, "\n")

w.Flush()
}
return nil
}

func displayProfiles(configuration *config.Config) {
profileSections := configuration.GetProfileSections()
keys := sortedMapKeys(profileSections)
Expand Down

0 comments on commit 06f98e9

Please sign in to comment.