diff --git a/.goreleaser.yml b/.goreleaser.yml index c97f90c..2d9cc42 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 @@ -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 @@ -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 diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..7974b0f --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,62 @@ +/* +Copyright © 2021 Remi Ferrand + +Contributor(s): Remi Ferrand , 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") +} diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..9262424 --- /dev/null +++ b/version/version.go @@ -0,0 +1,43 @@ +/* +Copyright © 2021 Remi Ferrand + +Contributor(s): Remi Ferrand , 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" +)