utils

package
v0.0.0-...-dc68900 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2014 License: BSD-3-Clause Imports: 6 Imported by: 0

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

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

func Exists(path string) (bool, error)

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

func GetSetting(name string) string

GetSetting retrieves the value for the given setting.

func GetSettings

func GetSettings() map[string]string

GetSettings returns a list of all the settings

func HasSetting

func HasSetting(name string) bool

HasSettings checks if the configuration has the given setting. It returns false if the setting does not exist.

func InteractiveInput

func InteractiveInput(prompt string) string

InteractiveInput shows a prompt and then reads a String provided by a user at a command-line.

func IsSettingBool

func IsSettingBool(name string) bool

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

func PaddingLeft(str, pad string, lenght int) string

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

func PaddingRight(str, pad string, lenght int) string

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

func SanitizeInput(input string) string

SanitizeInput applies the following rules iteratively until no further processing can be done:

  1. trim all the extra white spaces
  2. trim all return carriage chars
  3. trim leading / ending quotation marks (ex.: "my text")
  4. trim leading / ending spaces

func SetSetting

func SetSetting(name string, value string) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL