Skip to content

Commit

Permalink
Add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
riton committed Sep 13, 2021
1 parent 15a4f64 commit ca9e7b2
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ builds:
- linux
- windows
- darwin
binary: 'ensap'
binary: "ensap"
ldflags: "-s -w -X github.com/riton/ensap-cli/version.Version={{.Version}} -X github.com/riton/ensap-cli/version.Commit={{.Commit}} -X github.com/riton/ensap-cli/version.BuildDate={{.Date}}"
archives:
- replacements:
darwin: Darwin
Expand All @@ -18,19 +19,19 @@ archives:
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"

# Generate DEB and RPM using NFPM
nfpms:
- file_name_template: '{{ .ProjectName }}_{{ .Arch }}'
- file_name_template: "{{ .ProjectName }}_{{ .Arch }}"
homepage: https://github.com/riton/ensap-cli
description: Ensap (https://ensap.gouv.fr) CLI - L'espace numérique sécurisé de l'agent public
maintainer: Remi Ferrand <riton.github_at_gmail.com>
Expand All @@ -40,7 +41,7 @@ nfpms:
- apk
- deb
- rpm
bindir: '/usr/bin'
bindir: "/usr/bin"
contents:
- src: ./_examples/ensap.yaml
dst: /usr/share/{{ .ProjectName }}/ensap.sample.yaml
62 changes: 62 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright © 2021 Remi Ferrand
Contributor(s): Remi Ferrand <riton.github_at_gmail(dot)com>, 2021
This software is a computer program whose purpose is to interact with
the ENSAP API (ensap.gouv.fr).
This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.
*/
package cmd

import (
"fmt"

"github.com/riton/ensap-cli/version"
"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display software version and exit",
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetCount("verbose")
if verbosity == 0 {
fmt.Printf("%s\n", version.Version)
} else {
fmt.Printf("%s (git %s, built on %s)\n", version.Version, version.Commit, version.BuildDate)
}
},
}

func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.Flags().CountP("verbose", "v", "Increase verbosity")
}
43 changes: 43 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright © 2021 Remi Ferrand
Contributor(s): Remi Ferrand <riton.github_at_gmail(dot)com>, 2021
This software is a computer program whose purpose is to interact with
the ENSAP API (ensap.gouv.fr).
This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.
*/
package version

// Those are fed by the goreleaser tool
var (
Version = "dev"
Commit = "none"
BuildDate = "none"
)

0 comments on commit ca9e7b2

Please sign in to comment.