go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/blogctl/pkg/config/read_config.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package config
     9  
    10  import (
    11  	"github.com/urfave/cli/v2"
    12  	"go.charczuk.com/sdk/configutil"
    13  )
    14  
    15  // ReadConfig reads a config at a given path as yaml.
    16  func ReadConfig(ctx *cli.Context) (cfg Config, flags Flags, configPaths []string, err error) {
    17  	flags.Config = ctx.String(FlagConfig)
    18  	flags.DryRun = ctx.Bool(FlagDryRun)
    19  	flags.Parallelism = ctx.Int(FlagParallelism)
    20  
    21  	configPaths, err = configutil.Read(&cfg,
    22  		configutil.OptAddPreferredPaths(flags.Config),
    23  	)
    24  	if configutil.IsIgnored(err) {
    25  		err = nil
    26  	}
    27  	return
    28  }