ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - schachmat/ingo: persistent storage for flags in go
persistent storage for flags in go. Contribute to schachmat/ingo development by creating an account on GitHub.
Visit Site

GitHub - schachmat/ingo: persistent storage for flags in go

GitHub - schachmat/ingo: persistent storage for flags in go

Godoc Go Report Card Coverage

ingo is a simple Go library helping you to persist flags in a ini-like config file.

Features and limitations

  • Requires Go 1.5 or later
  • automatically creates config file, if it does not exist yet
  • option value priorities (from high to low): 0. flags given on the commandline 0. flags read from the config file 0. defaults given when flags are initialized
  • write defaults to config file, if they are not set there already
  • every flag in the config file has the flag usage prepended as a comment
  • shorthand flags pointing to the same variable as another flag will not be written to the config file to reduce noise. Both short and long version will still show up in the -h output.
  • only rewrite the config file, when it would change
  • old flags, which are not used anymore are not removed
  • when old flags are found, a warning is printed to stderr (see example below)
  • flags must not contain the runes : and = and not start with # as these runes are used as separators and comment prefix in the config file
  • no sections, namespaces or FlagSets other than the default one

Installation

go get -u github.com/schachmat/ingo

Usage example

Just setup your flags with defaults like you are used to do. Instead of flag.Parse() you have to call ingo.Parse(APPLICATION_NAME) and check if an error is returned. Thats all.

package main

import (
	"flag"
	"fmt"
	"log"
	"github.com/schachmat/ingo"
)

func main() {
	num := flag.Int("num", 3, "`NUMBER` of times to\n    \tdo a barrel roll")
	location := flag.String("location", "space", "`WHERE` to do the barrel roll")
	flag.StringVar(location, "l", "space", "`WHERE` to do the barrel roll (shorthand)")
	if err := ingo.Parse("keep_rollin"); err != nil {
		log.Fatal(err)
	}
	fmt.Println(*num, *location)
}

The (one newline, four spaces, one tab) separator will ensure that multi-line usage strings will be laid out correctly in the config file and in the -h help message. The code will create the following config file .keep_rollinrc (or any other location if specified in the environment variable KEEP_ROLLINRC):

# WHERE to do the barrel roll
location=space

# NUMBER of times to
# do a barrel roll
num=3

If you change num to 5 in the config file, it will be persistent on all future runs:

# WHERE to do the barrel roll
location=space

# NUMBER of times to
# do a barrel roll
num=5

If you add a new flag style to your programm, it will be added to the config file on the first run using the default value from the flag:

# WHERE to do the barrel roll
location=space

# NUMBER of times to
# do a barrel roll
num=5

# HOW to do the barrel roll
style=epic

If you remove both location flags from your programm, the config entry will be rewritten to this:

# NUMBER of times to
# do a barrel roll
num=5

# HOW to do the barrel roll
style=epic


# The following options are probably deprecated and not used currently!
location=space

Also when such old flags are found, a warning like the following is printed to stderr when running ingo.Parse:

!!!!!!!!!!
! WARNING: keep_rollin was probably updated,
! Check and update .keep_rollinrc as necessary
! and remove the last "deprecated" paragraph to disable this message!
!!!!!!!!!!

All config files will have a header like the following explaining the syntax:

# keep_rollin configuration
#
# This config has https://github.com/schachmat/ingo syntax.
# Empty lines or lines starting with # will be ignored.
# All other lines must look like "KEY=VALUE" (without the quotes).
# The VALUE must not be enclosed in quotes as well!

License - ISC

Copyright (c) 2016-2017, [email protected]

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory