-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add version command `astro version` will print the version of astro at the command line. Version information will be set using ldflags at release time. For more information, see: https://stackoverflow.com/questions/11354518/golang-application-auto-build-versioning Automated releasing is implemented in a separate PR.
- Loading branch information
1 parent
c972a31
commit bc39594
Showing
4 changed files
with
142 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2019 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Package cmd contains the source for the `astro` command line tool | ||
// that operators use to interact with the project. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
// When a release happens, the value of this variable will be overwritten | ||
// by the linker to match the release version. | ||
version = "dev" | ||
commit = "" | ||
date = "" | ||
) | ||
|
||
func (cli *AstroCLI) createVersionCmd() { | ||
versionCmd := &cobra.Command{ | ||
Use: "version", | ||
DisableFlagsInUseLine: true, | ||
Short: "Print astro version", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
versionString := []string{ | ||
"astro version", | ||
version, | ||
} | ||
|
||
if commit != "" { | ||
versionString = append(versionString, fmt.Sprintf("(%s)", commit)) | ||
} | ||
|
||
if date != "" { | ||
versionString = append(versionString, fmt.Sprintf("built %s", date)) | ||
} | ||
|
||
fmt.Fprintln(cli.stdout, strings.Join(versionString, " ")) | ||
|
||
return nil | ||
}, | ||
} | ||
cli.commands.version = versionCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters