mirror of
https://github.com/docker/compose.git
synced 2026-08-27 03:45:29 +00:00
Add version to UserAgent on ACI
This also refactors the Version insertion to make it global Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
parent
cda66b5e90
commit
10632b008b
6 changed files with 44 additions and 16 deletions
|
|
@ -26,18 +26,19 @@ import (
|
|||
"github.com/docker/compose-cli/cli/cmd/mobyflags"
|
||||
"github.com/docker/compose-cli/cli/mobycli"
|
||||
"github.com/docker/compose-cli/formatter"
|
||||
"github.com/docker/compose-cli/internal"
|
||||
)
|
||||
|
||||
const formatOpt = "format"
|
||||
|
||||
// VersionCommand command to display version
|
||||
func VersionCommand(version string) *cobra.Command {
|
||||
func VersionCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show the Docker version information",
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
Run: func(cmd *cobra.Command, _ []string) {
|
||||
runVersion(cmd, version)
|
||||
runVersion(cmd)
|
||||
},
|
||||
}
|
||||
// define flags for backward compatibility with com.docker.cli
|
||||
|
|
@ -49,15 +50,15 @@ func VersionCommand(version string) *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func runVersion(cmd *cobra.Command, version string) {
|
||||
func runVersion(cmd *cobra.Command) {
|
||||
var versionString string
|
||||
format := strings.ToLower(strings.ReplaceAll(cmd.Flag(formatOpt).Value.String(), " ", ""))
|
||||
displayedVersion := strings.TrimPrefix(version, "v")
|
||||
displayedVersion := strings.TrimPrefix(internal.Version, "v")
|
||||
// Replace is preferred in this case to keep the order.
|
||||
switch format {
|
||||
case formatter.PRETTY, "":
|
||||
versionString = strings.Replace(getOutFromMoby(cmd, fixedPrettyArgs(os.Args[1:])...),
|
||||
"\n Version:", "\n Cloud integration: "+displayedVersion+"\n Version:", 1)
|
||||
"\n Version:", "\n Cloud integration: "+displayedVersion+"\n Version:", 1)
|
||||
case formatter.JSON, formatter.TemplateJSON: // Try to catch full JSON formats
|
||||
versionString = strings.Replace(getOutFromMoby(cmd, fixedJSONArgs(os.Args[1:])...),
|
||||
`"Version":`, fmt.Sprintf(`"CloudIntegration":%q,"Version":`, displayedVersion), 1)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import (
|
|||
"github.com/docker/compose-cli/cli/cmd/login"
|
||||
"github.com/docker/compose-cli/cli/cmd/logout"
|
||||
"github.com/docker/compose-cli/cli/cmd/run"
|
||||
volume "github.com/docker/compose-cli/cli/cmd/volume"
|
||||
"github.com/docker/compose-cli/cli/cmd/volume"
|
||||
"github.com/docker/compose-cli/cli/mobycli"
|
||||
cliopts "github.com/docker/compose-cli/cli/options"
|
||||
"github.com/docker/compose-cli/config"
|
||||
|
|
@ -54,10 +54,6 @@ import (
|
|||
_ "github.com/docker/compose-cli/local"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
)
|
||||
|
||||
var (
|
||||
contextAgnosticCommands = map[string]struct{}{
|
||||
"compose": {},
|
||||
|
|
@ -122,7 +118,7 @@ func main() {
|
|||
cmd.InspectCommand(),
|
||||
login.Command(),
|
||||
logout.Command(),
|
||||
cmd.VersionCommand(version),
|
||||
cmd.VersionCommand(),
|
||||
cmd.StopCommand(),
|
||||
cmd.KillCommand(),
|
||||
cmd.SecretCommand(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue