Files
terraform-docs/cmd/version/version.go
Khosrow Moossavi 6820b4c2ce Normalize version to prevent malformed error
As part of this normalization the following is made sure:

- leading `v` is shown in `-v, --version` and `version` command
- commit hash is shown in `-v, --version` and `version` command
- build date is removed
- version core (without pre-release) is used for constraint comparison

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
2021-05-26 13:22:30 -04:00

49 lines
1.1 KiB
Go

/*
Copyright 2021 The terraform-docs Authors.
Licensed under the MIT license (the "License"); you may not
use this file except in compliance with the License.
You may obtain a copy of the License at the LICENSE file in
the root directory of this source tree.
*/
package version
import (
"fmt"
"github.com/spf13/cobra"
"github.com/terraform-docs/terraform-docs/internal/plugin"
"github.com/terraform-docs/terraform-docs/internal/version"
)
// NewCommand returns a new cobra.Command for 'version' command
func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Args: cobra.NoArgs,
Use: "version",
Short: "Print the version number of terraform-docs",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("terraform-docs version %s\n", version.Full())
plugins, err := plugin.Discover()
if err != nil {
return
}
for _, f := range plugins.All() {
name, err := f.Name()
if err != nil {
name = "unknown"
}
version, err := f.Version()
if err != nil {
version = "unknown"
}
fmt.Printf("- plugin %s %s\n", name, version)
}
},
}
return cmd
}