From 56f361a435b7f9835162db17f68eb63f417a4e78 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Tue, 19 Aug 2025 22:54:03 +0200 Subject: [PATCH] added readme --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..525c1ec --- /dev/null +++ b/README.md @@ -0,0 +1,63 @@ +# What is this? + +A super dim library for clis. It is intended to be 5% of the work for 60% of +the results. + +# Usage + +example: + +```go +package main + +import ( + "github.com/roodletoof/dim-cli" + _ "embed" +) + +// note: main.go is *this* source file + +//go:embed main.go +var thisFile string + +func main() { + dimcli.Help(thisFile) + var age = dimcli.GetPositional[int]() + var names = dimcli.GetKeyed( + "names", + []string{"Alice", "Bob"}, + ) + var printBar = dimcli.Flag("print-bar") + // HELP STOP + + println(age) + for _, name := range names { + println(name) + } + if printBar { + println("bar") + } +} +``` + +The above program supports required positional parameters, optional keyed +parameters, e.g. "--key value", flags "--some-flag", and a simple --help +command. + +If anything is wrong with the arguments provided the program will panic with a +pretty descriptive message. I think this is appropriate for most situations. + +The Help function expects you to provide a string that contains the source code +of where it was called. Use the embed package for this as in the example. It +will print out all the source code between the call and the first instance +where "HELP STOP" is found in the source code, if the --help flag is given to +the program. + +The library does not check that you don't provide extra arguments, it only +cares whether the arguments it tries to parse exist. + +Positional arguments and keyed arguments are parsed via the json package, so if +you want to provide a list in the example above you would put this in the +argument list: --names '["name1", "name2"]' + +This is super scuffed, and I hope you enjoy :)