github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/version/version.go (about) 1 // This file is part of arduino-cloud-cli. 2 // 3 // Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/) 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published 7 // by the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 package version 19 20 import "fmt" 21 22 var ( 23 defaultVersionString = "0.0.0-git" 24 versionString = "" 25 commit = "" 26 date = "" 27 VersionInfo *info 28 ) 29 30 type info struct { 31 Application string `json:"Application"` 32 VersionString string `json:"VersionString"` 33 Commit string `json:"Commit"` 34 Date string `json:"Date"` 35 } 36 37 func newInfo(application string) *info { 38 return &info{ 39 Application: application, 40 VersionString: versionString, 41 Commit: commit, 42 Date: date, 43 } 44 } 45 46 func (i *info) String() string { 47 return fmt.Sprintf("%s Version: %s Commit: %s Date: %s", i.Application, i.VersionString, i.Commit, i.Date) 48 } 49 50 func init() { 51 if versionString == "" { 52 versionString = defaultVersionString 53 } 54 VersionInfo = newInfo("arduino-cloud-cli") 55 }