Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/pkazmier/ffyaml

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/pkazmier/ffyaml

  • v0.0.0-20230717225006-874981b21151
  • Source
  • Go
  • Socket score

Version published
Created
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 a WithKeyPath option 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"))

	// 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

Package last updated on 17 Jul 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc