github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/cmd/config.go (about)

     1  /*
     2   * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved.
     3   * This software is released under GPL3.
     4   * The full license information can be found under:
     5   * https://www.gnu.org/licenses/gpl-3.0.en.html
     6   *
     7   */
     8  
     9  package cmd
    10  
    11  import (
    12  	"fmt"
    13  	"github.com/vchain-us/vcn/pkg/extractor/nodecom"
    14  	"os"
    15  
    16  	"github.com/vchain-us/vcn/pkg/extractor"
    17  	"github.com/vchain-us/vcn/pkg/extractor/dir"
    18  	"github.com/vchain-us/vcn/pkg/extractor/docker"
    19  	"github.com/vchain-us/vcn/pkg/extractor/dotnetcom"
    20  	"github.com/vchain-us/vcn/pkg/extractor/file"
    21  	"github.com/vchain-us/vcn/pkg/extractor/git"
    22  	"github.com/vchain-us/vcn/pkg/extractor/gocom"
    23  	"github.com/vchain-us/vcn/pkg/extractor/javacom"
    24  	"github.com/vchain-us/vcn/pkg/extractor/pythoncom"
    25  	"github.com/vchain-us/vcn/pkg/extractor/wildcard"
    26  
    27  	"github.com/vchain-us/vcn/pkg/store"
    28  )
    29  
    30  // initConfig reads in config file and ENV variables if set.
    31  func initConfig() {
    32  
    33  	// Register metadata extractors
    34  	extractor.Register("", wildcard.Artifact)
    35  	extractor.Register(file.Scheme, file.Artifact)
    36  	extractor.Register(dir.Scheme, dir.Artifact)
    37  	extractor.Register(docker.Scheme, docker.Artifact)
    38  	extractor.Register(docker.SchemePodman, docker.Artifact)
    39  	extractor.Register(git.Scheme, git.Artifact)
    40  	extractor.Register(wildcard.Scheme, wildcard.Artifact)
    41  	extractor.Register(javacom.Scheme, javacom.Artifact)
    42  	extractor.Register(gocom.Scheme, gocom.Artifact)
    43  	extractor.Register(pythoncom.Scheme, pythoncom.Artifact)
    44  	extractor.Register(dotnetcom.Scheme, dotnetcom.Artifact)
    45  	extractor.Register(nodecom.Scheme, nodecom.Artifact)
    46  
    47  	// Load config
    48  	if cfgFile != "" {
    49  		store.SetConfigFile(cfgFile)
    50  		if output, _ := rootCmd.PersistentFlags().GetString("output"); output == "" {
    51  			fmt.Println("Using config file: ", store.ConfigFile())
    52  		}
    53  	}
    54  	if err := store.LoadConfig(); err != nil {
    55  		fmt.Println(err)
    56  		os.Exit(1)
    57  	}
    58  }