github.com/SUSE/skuba@v1.4.17/pkg/skuba/version.go (about)

     1  /*
     2   * Copyright (c) 2019 SUSE LLC.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   */
    17  
    18  package skuba
    19  
    20  import (
    21  	"fmt"
    22  	"runtime"
    23  )
    24  
    25  var (
    26  	Version    string
    27  	BuildDate  string
    28  	Tag        string
    29  	ClosestTag string
    30  )
    31  
    32  type SkubaVersion struct {
    33  	Version   string
    34  	BuildType string
    35  	BuildDate string
    36  	Tag       string
    37  	GoVersion string
    38  }
    39  
    40  func CurrentVersion() SkubaVersion {
    41  	skubaVersion := SkubaVersion{
    42  		Version:   Version,
    43  		BuildType: BuildType,
    44  		BuildDate: BuildDate,
    45  		Tag:       Tag,
    46  		GoVersion: runtime.Version(),
    47  	}
    48  	if skubaVersion.Tag == "" {
    49  		skubaVersion.Version = fmt.Sprintf("untagged (%s)", ClosestTag)
    50  	}
    51  	return skubaVersion
    52  }
    53  
    54  func (s SkubaVersion) String() string {
    55  	if s.Tag == "" {
    56  		return fmt.Sprintf("skuba version: %s (%s) %s %s", s.Version, s.BuildType, s.BuildDate, s.GoVersion)
    57  	}
    58  	return fmt.Sprintf("skuba version: %s (%s) (tagged as %q) %s %s", s.Version, s.BuildType, s.Tag, s.BuildDate, s.GoVersion)
    59  }