github.com/gohugoio/hugo@v0.88.1/commands/env.go (about)

     1  // Copyright 2016 The Hugo Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package commands
    15  
    16  import (
    17  	"runtime"
    18  
    19  	"github.com/gohugoio/hugo/common/hugo"
    20  
    21  	"github.com/spf13/cobra"
    22  	jww "github.com/spf13/jwalterweatherman"
    23  )
    24  
    25  var _ cmder = (*envCmd)(nil)
    26  
    27  type envCmd struct {
    28  	*baseCmd
    29  }
    30  
    31  func newEnvCmd() *envCmd {
    32  	return &envCmd{
    33  		baseCmd: newBaseCmd(&cobra.Command{
    34  			Use:   "env",
    35  			Short: "Print Hugo version and environment info",
    36  			Long: `Print Hugo version and environment info. This is useful in Hugo bug reports.
    37  
    38  If you add the -v flag, you will get a full dependency list.
    39  `,
    40  			RunE: func(cmd *cobra.Command, args []string) error {
    41  				printHugoVersion()
    42  				jww.FEEDBACK.Printf("GOOS=%q\n", runtime.GOOS)
    43  				jww.FEEDBACK.Printf("GOARCH=%q\n", runtime.GOARCH)
    44  				jww.FEEDBACK.Printf("GOVERSION=%q\n", runtime.Version())
    45  
    46  				isVerbose, _ := cmd.Flags().GetBool("verbose")
    47  
    48  				if isVerbose {
    49  					deps := hugo.GetDependencyList()
    50  					for _, dep := range deps {
    51  						jww.FEEDBACK.Printf("%s\n", dep)
    52  					}
    53  				}
    54  
    55  				return nil
    56  			},
    57  		}),
    58  	}
    59  
    60  }