...

Source file src/github.com/pelletier/go-toml/v2/cmd/tomll/main.go

Documentation: github.com/pelletier/go-toml/v2/cmd/tomll

     1  // Package tomll is a linter program for TOML.
     2  //
     3  // # Usage
     4  //
     5  // Reading from stdin, writing to stdout:
     6  //
     7  //	cat file.toml | tomll
     8  //
     9  // Reading and updating a list of files in place:
    10  //
    11  //	tomll a.toml b.toml c.toml
    12  //
    13  // # Installation
    14  //
    15  // Using Go:
    16  //
    17  //	go install github.com/pelletier/go-toml/v2/cmd/tomll@latest
    18  package main
    19  
    20  import (
    21  	"io"
    22  
    23  	"github.com/pelletier/go-toml/v2"
    24  	"github.com/pelletier/go-toml/v2/internal/cli"
    25  )
    26  
    27  const usage = `tomll can be used in two ways:
    28  
    29  Reading from stdin, writing to stdout:
    30    cat file.toml | tomll > file.toml
    31  
    32  Reading and updating a list of files in place:
    33    tomll a.toml b.toml c.toml
    34  
    35  When given a list of files, tomll will modify all files in place without asking.
    36  `
    37  
    38  func main() {
    39  	p := cli.Program{
    40  		Usage:   usage,
    41  		Fn:      convert,
    42  		Inplace: true,
    43  	}
    44  	p.Execute()
    45  }
    46  
    47  func convert(r io.Reader, w io.Writer) error {
    48  	var v interface{}
    49  
    50  	d := toml.NewDecoder(r)
    51  	err := d.Decode(&v)
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	e := toml.NewEncoder(w)
    57  	return e.Encode(v)
    58  }
    59  

View as plain text