Socket
Socket
Sign inDemoInstall

github.com/pkazmier/ffyaml

Package Overview
Dependencies
2
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/pkazmier/ffyaml

Package ffyaml provides a YAML config file parser.


Version published

Readme

Source

ffyaml

This is a YAML configuration parser for the excellent peterbourgon/ff module. It is a fork of the ffyaml parser included that module. This fork provides the WithKeyPath and WithAllowMissingKeyPath options to specify the location within the YAML document where the configuration resides. It allows one to use a subset of a larger configuration file.

Usage

Given the following configuration file:

name: Super Configuration
plugins:
  cli:
    verbose: true
    workers: 20

The following program will parse the options from it:

import (
	"flag"
	"fmt"
	"os"

	"github.com/peterbourgon/ff/v3"
	"github.com/pkazmier/ffyaml"
)

func main() {

	// Define a `flag.FlagSet`
	fs := flag.NewFlagSet("example", flag.ContinueOnError)
	verbose := fs.Bool("verbose", false, "enable verbose logging")
	workers := fs.Int("workers", 10, "number of workers to create")

	// Define the YAML configuration parser that points to the `cli` section:
	parser := ffyaml.New(
		ffyaml.WithKeyPath("plugins", "cli"),
		ffyaml.WithAllowMissingKeyPath(true),
	)

	// Then invoke `peterbourgon/ff.Parse` with this YAML configuration parser:
	err := ff.Parse(fs, os.Args[1:],
		ff.WithConfigFile("config.yaml"),
		ff.WithConfigFileParser(parser.Parse),
	)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Printf("verbose = %v\n", *verbose)
	fmt.Printf("workers = %v\n", *workers)
}

FAQs

Last updated on 17 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc