Documentation ¶
Overview ¶
Package utils provides helper functions for applications that need to interact with Todo.txt CLI files.
A complete Todo.txt configuration representation can be retrieved as follows:
package main import ( "fmt" "github.com/toffanin/go-todo/utils" ) func main() { // Load Todo.txt CLI settings from todo.cfg utils.LoadConfig() settings := utils.GetSettings() fmt.Printf("Settings: %#v\n", settings) // now continue with your app and do something useful with settings }
Single configuration values can be retrieved as follow:
func main() { todoDir := utils.GetSetting("TODO_DIR") todoActionsDir := utils.GetSetting("TODO_ACTIONS_DIR") // do something with todoDir and todoActionsDir }
Index ¶
- func Check(e error)
- func Exists(path string) (bool, error)
- func GetHome() string
- func GetPwd() string
- func GetSetting(name string) string
- func GetSettings() map[string]string
- func HasSetting(name string) bool
- func InteractiveInput(prompt string) string
- func IsSettingBool(name string) bool
- func LoadConfig()
- func PaddingLeft(str, pad string, lenght int) string
- func PaddingRight(str, pad string, lenght int) string
- func SanitizeInput(input string) string
- func SetSetting(name string, value string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(e error)
(WIP) This function is an ugly and hackish error handler that needs to be replaced with something more complete and useful. Don't use it.
func Exists ¶
Exists returns true if the given path exists. The path can be both a file or a directory.
func GetHome ¶
func GetHome() string
GetHome retrieves the value of the environment variable named $HOME.
func GetPwd ¶
func GetPwd() string
GetPwd retrieves the path name corresponding to the current directory.
func GetSetting ¶
GetSetting retrieves the value for the given setting.
func GetSettings ¶
GetSettings returns a list of all the settings
func HasSetting ¶
HasSettings checks if the configuration has the given setting. It returns false if the setting does not exist.
func InteractiveInput ¶
InteractiveInput shows a prompt and then reads a String provided by a user at a command-line.
func IsSettingBool ¶
Looks up the value of a setting, returns false if no bool value exists.
func LoadConfig ¶
func LoadConfig()
LoadConfig reads all the configuration files (todo.cfg) and then creates a configuration representation filled with keys and values.
Call this function as close as possible to the start of your application, ideally in main().
func PaddingLeft ¶
PaddingLeft creates a new string by concatenating enough leading pad characters to an original string to achieve a specified total length.
The following code example uses PaddingLeft to create a new string that is 5 characters long and padded on the left with zeros:
func main() { str := "12" fmt.Println(PaddingLeft(str, "0", 5)) // expects 00012 }
func PaddingRight ¶
PaddingRight creates a new string by concatenating enough trailing pad characters to an original string to achieve a specified total length.
The following code example uses PaddingRight to create a new string that is 5 characters long and padded on the right with zeros:
func main() { str := "12" fmt.Println(PaddingRight(str, "0", 5)) // expects 12000 }
func SanitizeInput ¶
SanitizeInput applies the following rules iteratively until no further processing can be done:
- trim all the extra white spaces
- trim all return carriage chars
- trim leading / ending quotation marks (ex.: "my text")
- trim leading / ending spaces
func SetSetting ¶
SetSetting adds a setting and a value to the configuration. It returns true if the setting and value were inserted.
Types ¶
This section is empty.