Skip to content

bash-bastion/bash-toml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bash-toml

Aspiring Toml v1.0.0 parser written in pure Bash

STATUS: EXPERIMENTAL

Usage

declare -A TOML=() source bash-toml <<-"EOF" five = 'value' EOF printf '%s' "${TOML[five]}" # value

Support

Support is generally limited at the moment

  • Construct: Comment
  • Construct: Key
  • Value: String (basic)
  • Value: String (literal)

Not Yet Supported

  • Value: String (multi-line basic)
  • Value: String (multi-line literal)
  • Value: Integer
  • Value: Float
  • Value: Boolean
  • Value: Offset Date-Time
  • Value: Local Date-Time
  • Value: Local Date
  • Value: Local Time
  • Value: Array
  • Value: Inline Table
  • Construct: Table
  • Construct Array of Tables

Error Handling

  1. Bail Fast

This means error handling is performed by bash-toml. More specifically, if there is a problem parsing, the script will exit. This is useful if you want to use bash-toml for a quick thing, and want to bail fast, irrespective of the errexit option. Of course, if you execute this in a subshell (potentially depending on the pipefail option), the main shell won't exit at all

# file.sh set +e source ./bash-toml.sh bash-toml <<< "key = '"
$ ./file.sh # => exitCode 1 Error: Could not finish single quote string, etc.
  1. Control

If you want to have more fine-grained control over your error handling

  • Note that this does not currently mask error output to stdin that builtins may emit when erroring
# file.sh set +e source ./bash-toml.sh TOML_MANUAL_ERROR='yes' if ! bash-toml <<< "key = '"; then if [ -n "$TOML_ERROR" ]; then # Problem with the 'file.toml' : else # Internal 'bash-toml' error exit 2 fi fi
$ ./file.sh # => exitCode 0

Caveats

  • When parsing literal strings, i think actual literal control characters are not taken into account
  • When parsing basic strings, any control characters that appear will show error "EOF" rather than one specific to control characters
    • this is generally true since no differentiation between a newline and EOF

About

A kickass Toml parser written in pure Bash

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages