All Projects → timjchin → Unpuzzled

timjchin / Unpuzzled

Licence: mit
A colorful CLI library with variable provenance.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Unpuzzled

Envy
Envy automatically exposes environment variables for all of your Go flags
Stars: ✭ 150 (+163.16%)
Mutual labels:  cli, flags
Jinja2 Cli
CLI for Jinja2
Stars: ✭ 302 (+429.82%)
Mutual labels:  cli, toml
Protodep
Collect necessary .proto files (Protocol Buffers IDL) and manage dependencies
Stars: ✭ 167 (+192.98%)
Mutual labels:  cli, toml
Cli
A simple, fast, and fun package for building command line apps in Go
Stars: ✭ 16,995 (+29715.79%)
Mutual labels:  cli, toml
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+10742.11%)
Mutual labels:  cli, toml
Staert
Merge your configuration sources
Stars: ✭ 108 (+89.47%)
Mutual labels:  cli, toml
Grumble
A powerful modern CLI and SHELL
Stars: ✭ 277 (+385.96%)
Mutual labels:  cli, flags
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+294.74%)
Mutual labels:  toml, flags
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+638.6%)
Mutual labels:  cli, toml
Args
Toolkit for building command line interfaces
Stars: ✭ 399 (+600%)
Mutual labels:  cli, flags
Mri
Quickly scan for CLI flags and arguments
Stars: ✭ 394 (+591.23%)
Mutual labels:  cli, flags
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+1231.58%)
Mutual labels:  cli, toml
Flaggy
Idiomatic Go input parsing with subcommands, positional values, and flags at any position. No required project or package layout and no external dependencies.
Stars: ✭ 711 (+1147.37%)
Mutual labels:  cli, flags
Hugo Elasticsearch
Generate Elasticsearch indexes for Hugo static sites by parsing front matter
Stars: ✭ 19 (-66.67%)
Mutual labels:  cli, toml
S4cmd
Super S3 command line tool
Stars: ✭ 1,076 (+1787.72%)
Mutual labels:  cli
Bangjago Android Emulator
simple android emulator cli for mobile development
Stars: ✭ 56 (-1.75%)
Mutual labels:  cli
Crex
Explore, test, and check regular expressions in the terminal.
Stars: ✭ 54 (-5.26%)
Mutual labels:  cli
Gg
A tool to manage multiple git repositories
Stars: ✭ 54 (-5.26%)
Mutual labels:  cli
Dress
👗 Dress up your stdout
Stars: ✭ 55 (-3.51%)
Mutual labels:  cli
Batchimageprocessor
A Mass Image Processing tool for Windows
Stars: ✭ 55 (-3.51%)
Mutual labels:  cli

Unpuzzled GoDoc Build Status

A user-first CLI library.

With the ability to import variables from many different sources: command line flags, environment variables, and configuration variables, it's often not clear what values are set, or why.

Unpuzzled gives you and your users a clear explanation of where variables are being set, and which ones are being overwritten.

Clarity prevents confusion.

Features

  • First class importing from:
    • Environment Variables
    • JSON files
    • TOML files
    • CLI Flags
  • Ability to choose the order of variable overrides (ex. cli flags > JSON > TOML > ENV)
  • Main Command and Subcommands
  • Defaults to verbose output out of the box, with the ability to turn it off. (app.Silent = true`)
  • Warnings on overrides
    • Warnings on overrides by order of precedence.
      • If a variable is set as an ENV variable, and a CLI flag overwrites it, let the user know.
      • If two or more variables have references to the same pointer, let the user know.
  • Displays what variables are set, and what they are set to.
  • Add default values for variables.
  • Ability to set Variables as Required.
    • If a value isn't set, print a warning to stdout, and exit.
    • If a variable has a Default value, it can never be marked as required, because a valid value will be set.

Left to do:

  • More variable types

Types of Outputs

Missing Required Variables:

Unpuzzled will parse all the inputs, and then list all of the missing required variables before exiting the program. This includes required variables in parent commands. required variables

Set Variables

Set Variables can be shown in two outputs.

Stdout is the default:

set variable stdout

Table Option

A table option can be chosen by setting OverridesOutputIntTable to true:

app := unpuzzled.NewApp()
app.OverridesOutputInTable = true

set variable table view

Overwritten Destination

Since unpuzzled uses pointers to set the final values, it's possible that the same pointer may be left in multiple variables.

Unpuzzled will warn you that these values have been overwritten.

In the example below, the variables example-a and example-b both point to testString. If both are set, example-b will override example-a, because it is later in the Variables array.

var testString string
app := unpuzzled.NewApp()
app.Command = &unpuzzled.Command{
    Variables: []unpuzzled.Variable{
        &unpuzzled.StringVariable{
            Name:        "example-a",
            Destination: &testString,
        },
        &unpuzzled.StringVariable{
            Name:        "example-b",
            Destination: &testString,
        },
    },
    Action: func() {
        fmt.Println(testString)
    },
}
app.Run(os.Args)

overwritten pointer

(Full example in examples/overwritten_pointer)

Help Text:

Help text is provided whenever the app is run with the values provided in the app.HelpCommands. The defaults are: -h, --help or help. The help text content only includes the content for the current command selected.

help text

How to use JSON / Toml configs:

TOML:
app := unpuzzled.NewApp()
app.Command = &unpuzzled.Command{
    Name: "main",
    Variables: []unpuzzled.Variable{
        &unpuzzled.ConfigVariable{
            StringVariable: &unpuzzled.StringVariable{
                Name: "config"
                Description: "Main configuration, use with `go run main.go --config=path_to_file.toml`",
                Type: unpuzzled.TomlConfig,
            },
        },
    },
}
JSON Config Example:
app := unpuzzled.NewApp()
app.Command = &unpuzzled.Command{
    Name: "main",
    Variables: []unpuzzled.Variable{
        &unpuzzled.ConfigVariable{
            StringVariable: &unpuzzled.StringVariable{
                Name: "config"
                Description: "Main configuration flag, use with `go run main.go --config=path_to_file.json`",
                Type: unpuzzled.JsonConfig,
            },
        },
    },
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].