### Install and Import Afero
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/afero/README.md
Demonstrates how to install the Afero library using 'go get' and how to import it into a Go project for use.
```go
import "github.com/spf13/afero"
```
--------------------------------
### Install Finder Library for Afero using Go
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/sagikazarmark/locafero/README.md
Demonstrates how to install the locafero library, which is a Finder library for Afero, using the Go get command. This is the standard method for adding Go packages to a project.
```shell
go get github.com/sagikazarmark/locafero
```
--------------------------------
### Install Viper using Go Modules
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
This snippet shows how to install the Viper library using the go get command. It highlights that Viper uses Go Modules for dependency management.
```shell
go get github.com/spf13/viper
```
--------------------------------
### Install and Upgrade properties Go Library
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/magiconair/properties/README.md
Provides the command to install or upgrade the properties Go library using the go get command. This ensures you have the latest version of the library for your project.
```bash
go get -u github.com/magiconair/properties
```
--------------------------------
### Install yaml package for Go
Source: https://github.com/variadico/noti/blob/main/vendor/gopkg.in/yaml.v3/README.md
This command installs the yaml v3 package for Go using the go get command. Ensure you have Go installed and configured.
```shell
go get gopkg.in/yaml.v3
```
--------------------------------
### Install mapstructure Go Library
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/mitchellh/mapstructure/README.md
This snippet shows the standard Go command to install the mapstructure library using 'go get'. It fetches the library and makes it available for use in your Go projects.
```bash
go get github.com/mitchellh/mapstructure
```
--------------------------------
### Testing with Afero MemMapFs
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/afero/README.md
Illustrates using Afero's MemMapFs for testing, providing a clean, reproducible, and fast file system environment. This example shows creating directories and files for a test scenario.
```go
func TestExist(t *testing.T) {
appFS := afero.NewMemMapFs()
// create test files and directories
appFS.MkdirAll("src/a", 0755)
afero.WriteFile(appFS, "src/a/b", []byte("file b"), 0644)
afero.WriteFile(appFS, "src/c", []byte("file c"), 0644)
name := "src/c"
_, err := appFS.Stat(name)
if os.IsNotExist(err) {
t.Errorf("file \"%s\" does not exist.\n", name)
}
}
```
--------------------------------
### Install Noti using Go
Source: https://github.com/variadico/noti/blob/main/docs/noti.md
Installs the latest version of the 'noti' command-line tool using the Go package manager.
```go
go get -u github.com/variadico/noti/cmd/noti
```
--------------------------------
### Install dbus Go Package
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/godbus/dbus/v5/README.md
Installs the D-Bus Go package using the go get command. This package requires Go 1.12 or later.
```go
go get github.com/godbus/dbus/v5
```
--------------------------------
### Use crypt CLI to Set Configuration
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Provides an example of using the `crypt` command-line tool to set configuration values in a key/value store. This includes fetching the tool and setting a plaintext configuration.
```bash
$ go get github.com/sagikazarmark/crypt/bin/crypt
$ crypt set -plaintext /config/hugo.json /Users/hugo/settings/config.json
```
--------------------------------
### Install slog-shim using go get
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/sagikazarmark/slog-shim/README.md
This command installs the slog-shim package using the Go package manager. It fetches the latest version from the repository.
```shell
go get github.com/sagikazarmark/slog-shim
```
--------------------------------
### Example Commit Message Format
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/godbus/dbus/v5/CONTRIBUTING.md
This example demonstrates the recommended format for commit messages, including the subsystem, a brief description of the change, and a more detailed explanation of the reasoning behind the change. It adheres to character limits for readability across different Git tools and platforms.
```git
scripts: add the test-cluster command
this uses tmux to setup a test cluster that you can easily kill and
start for debugging.
Fixes #38
```
--------------------------------
### Install conc Go Package
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/sourcegraph/conc/README.md
This command installs the 'conc' Go package, which provides structured concurrency utilities for Go programs. Ensure you have Go installed and configured.
```sh
go get github.com/sourcegraph/conc
```
--------------------------------
### Example test script syntax
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md
Demonstrates the format for creating new test cases using a shell-like syntax. This includes file operations and expected output, with support for comments and specific output formats.
```bash
# Create a new empty file with some data.
watch /
echo data >/file
Output:
create /file
write /file
```
--------------------------------
### Noti Configuration Example (YAML)
Source: https://github.com/variadico/noti/blob/main/docs/man/noti.yaml.5.md
A comprehensive example of a noti.yaml file showcasing various service configurations including sound settings, speech synthesis, and integrations with services like BearyChat, Keybase, Pushbullet, Pushover, Pushsafer, Simplepush, Slack, Twilio, and Gchat.
```yaml
---
nsuser:
soundName: Ping
soundNameFail: Basso
say:
voice: Alex
espeak:
voiceName: english-us
speechsynthesizer:
voice: Microsoft David Desktop
bearychat:
incomingHookURI: 1234567890abcdefg
keybase:
conversation: yourteam
channel: general
pushbullet:
accessToken: 1234567890abcdefg
deviceIden: 1234567890abcdefg
pushover:
userKey: 1234567890abcdefg
apiToken: 1234567890abcdefg
pushsafer:
key: 1234567890abcdefg
simplepush:
key: 1234567890abcdefg
event: 1234567890abcdefg
slack:
appurl: 'https://hooks.slack.com/services/xxx/yyy/zzz'
twilio:
numberto: '+972542877978'
numberfrom: '+18111119711'
accountsid: AC3cd135aa82XXXXXXXXf792ba23fc98
authtoken: 74efd0bXXXXXXXXXXX32f7daca
gchat:
appurl: 'https://chat.googleapis.com/v1/spaces/example/messages?key=keyexample'
template: '*{{.title}}*: {{.message}}'
```
--------------------------------
### Install tomll Tool (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Installs the tomll command-line tool from the go-toml v2 repository. This tool lints and reformats TOML files. It requires a Go development environment.
```go
go install github.com/pelletier/go-toml/v2/cmd/tomll@latest
```
--------------------------------
### Use crypt CLI to Get Configuration
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Shows how to retrieve configuration values from a key/value store using the `crypt` command-line tool, specifically for plaintext values.
```bash
$ crypt get -plaintext /config/hugo.json
```
--------------------------------
### Install Cobra Library
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/cobra/README.md
Installs the latest version of the Cobra library using the Go package manager.
```bash
go get -u github.com/spf13/cobra@latest
```
--------------------------------
### Use tomljson with Docker (Shell)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Runs the tomljson tool from a Docker container to convert an example TOML file to JSON. This demonstrates using the tool without local installation.
```shell
docker run -i ghcr.io/pelletier/go-toml:v2 tomljson < example.toml
```
--------------------------------
### Install jsontoml Tool (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Installs the jsontoml command-line tool from the go-toml v2 repository. This tool converts JSON files to their TOML representation. It requires a Go development environment.
```go
go install github.com/pelletier/go-toml/v2/cmd/jsontoml@latest
```
--------------------------------
### Write Configuration Files with Viper (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Provides examples for writing the current Viper configuration to a file. It includes methods for writing to a predefined path, safely writing (avoiding overwrites), writing to a specific path, and safely writing to a specific path.
```Go
viper.WriteConfig() // writes current config to predefined path set by 'viper.AddConfigPath()' and 'viper.SetConfigName'
vIper.SafeWriteConfig()
vIper.WriteConfigAs("/path/to/my/.config")
vIper.SafeWriteConfigAs("/path/to/my/.config") // will error since it has already been written
vIper.SafeWriteConfigAs("/path/to/my/.other_config")
```
--------------------------------
### Go Modules FAQ Link
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Provides a link to the Go Modules FAQ for assistance with common issues, particularly related to 'go get' failures when trying to find the main module.
```html
Go Modules FAQ
```
--------------------------------
### Run Cobra Tests
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/cobra/CONTRIBUTING.md
This snippet shows commands to run tests and format code for the Cobra project. It requires Go and Make to be installed.
```shell
go test ./...
make test
make all
```
--------------------------------
### Install tomljson Tool (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Installs the tomljson command-line tool from the go-toml v2 repository. This tool converts TOML files to their JSON representation. It requires a Go development environment.
```go
go install github.com/pelletier/go-toml/v2/cmd/tomljson@latest
```
--------------------------------
### Install Cobra CLI Generator
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/cobra/README.md
Installs the cobra-cli tool, used for generating Cobra application and command files.
```bash
go install github.com/spf13/cobra-cli@latest
```
--------------------------------
### Install go-ini/ini Package
Source: https://github.com/variadico/noti/blob/main/vendor/gopkg.in/ini.v1/README.md
Installs the go-ini/ini package using the Go module system. It's recommended to use the -u flag for future updates.
```shell
go get gopkg.in/ini.v1
```
--------------------------------
### Load Properties from Various Sources in Go
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/magiconair/properties/README.md
Demonstrates how to load properties files using the properties library in Go. It shows examples of loading from a single file, multiple files, a map, a string, URLs, and command-line flags. The library supports UTF-8 encoding and environment variable expansion within file paths.
```go
import (
"flag"
"github.com/magiconair/properties"
"time"
"log"
)
func main() {
// init from a file
p := properties.MustLoadFile("${HOME}/config.properties", properties.UTF8)
// or multiple files
p = properties.MustLoadFiles([]string{
"${HOME}/config.properties",
"${HOME}/config-${USER}.properties",
}, properties.UTF8, true)
// or from a map
p = properties.LoadMap(map[string]string{"key": "value", "abc": "def"})
// or from a string
p = properties.MustLoadString("key=value\nabc=def")
// or from a URL
p = properties.MustLoadURL("http://host/path")
// or from multiple URLs
p = properties.MustLoadURL([]string{
"http://host/config",
"http://host/config-${USER}",
}, true)
// or from flags
p.MustFlag(flag.CommandLine)
// get values through getters
host := p.MustGetString("host")
port := p.GetInt("port", 8080)
// or through Decode
type Config struct {
Host string `properties:"host"`
Port int `properties:"port,default=9000"`
Accept []string `properties:"accept,default=image/png;image;gif"`
Timeout time.Duration `properties:"timeout,default=5s"`
}
var cfg Config
if err := p.Decode(&cfg); err != nil {
log.Fatal(err)
}
}
```
--------------------------------
### Install go-toml v2 (Go Modules)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Installs the go-toml v2 library using Go modules for projects managed with Go version 1.13 or later. It ensures the latest version is fetched and available for import.
```go
GO111MODULE=on go get github.com/pelletier/go-toml/v2
```
--------------------------------
### Install Noti using Homebrew (macOS)
Source: https://github.com/variadico/noti/blob/main/docs/noti.md
Installs the latest version of 'noti' on macOS using the Homebrew package manager.
```shell
brew install noti
```
--------------------------------
### Marshalling Viper Settings to YAML String
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Illustrates how to convert all current Viper settings into a YAML formatted string. This is achieved by calling `AllSettings()` to get a map of all configurations and then using a YAML marshaller like `gopkg.in/yaml.v2` to serialize it.
```go
import (
yaml "gopkg.in/yaml.v2"
// ...
)
func yamlStringSettings() string {
c := viper.AllSettings()
bs, err := yaml.Marshal(c)
if err != nil {
log.Fatalf("unable to marshal config to YAML: %v", err)
}
return string(bs)
}
```
--------------------------------
### Getting Configuration Values with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
This Go snippet illustrates various methods provided by the Viper library to retrieve configuration values. It covers retrieving values by type (string, bool, int, float64, slices, maps, time, duration) and checking for the existence of a key using IsSet(). It also mentions that Get methods return a zero value if a key is not found or fails to parse.
```go
viper.GetString("logfile") // case-insensitive Setting & Getting
if viper.GetBool("verbose") {
fmt.Println("verbose enabled")
}
```
--------------------------------
### Install Multierr Package
Source: https://github.com/variadico/noti/blob/main/vendor/go.uber.org/multierr/README.md
This command installs the latest version of the multierr package from Uber Go using the Go module system.
```bash
go get -u go.uber.org/multierr@latest
```
--------------------------------
### Install Noti using Brew on macOS
Source: https://github.com/variadico/noti/blob/main/README.md
Installs the Noti binary on macOS using the Homebrew package manager. This is a straightforward method for users who have Homebrew set up.
```shell
# macOS install with Brew
brew install noti
```
--------------------------------
### Fetch Configuration from Firestore with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Shows how to use Viper to get configuration from Google Cloud Firestore. It requires the Google Cloud project ID and the path to the configuration document.
```go
viper.AddRemoteProvider("firestore", "google-cloud-project-id", "collection/document")
viper.SetConfigType("json")
err := viper.ReadRemoteConfig()
```
--------------------------------
### Extracting Configuration Sub-tree with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Demonstrates how to extract a specific section of the configuration using Viper's Sub() method. This is useful for passing isolated configuration to modules or components, enhancing reusability and testability. The example shows creating a new Viper instance for a sub-tree and accessing its values.
```go
cache1Config := viper.Sub("cache.cache1")
if cache1Config == nil { // Sub returns nil if the key cannot be found
panic("cache configuration not found")
}
cache1 := NewCache(cache1Config)
```
```go
func NewCache(v *Viper) *Cache {
return &Cache{
MaxItems: v.GetInt("max-items"),
ItemSize: v.GetInt("item-size"),
}
}
```
--------------------------------
### HCL Multi-line String Example
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/hashicorp/hcl/README.md
Demonstrates how to define multi-line strings in HCL using a here-document syntax, similar to shell scripting. The delimiter can be any string, and it must appear on its own line to terminate the string.
```HCL
<)
fileserver := http.FileServer(httpFs.Dir())
http.Handle("/", fileserver)
```
--------------------------------
### Read Config File with Viper (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Demonstrates how to configure Viper to find and read configuration files. It covers setting the configuration file name, type, and search paths, as well as handling potential errors during the read process.
```Go
viper.SetConfigName("config") // name of config file (without extension)
vIper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
vIper.AddConfigPath("/etc/appname/") // path to look for the config file in
vIper.AddConfigPath("$HOME/.appname") // call multiple times to add many search paths
vIper.AddConfigPath(".") // optionally look in the working directory
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file: %w", err))
}
```
```Go
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found; ignore error if desired
} else {
// Config file was found but another error was produced
}
}
```
--------------------------------
### Fetch Configuration from etcd with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Shows how to configure Viper to read configuration from etcd. It specifies the etcd endpoint, the configuration path, and the configuration type. Requires the `viper/remote` package.
```go
viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001","/config/hugo.json")
viper.SetConfigType("json")
err := viper.ReadRemoteConfig()
```
--------------------------------
### Custom Flag Name Normalization (Aliasing)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/pflag/README.md
Demonstrates creating a custom flag name normalization function to alias flags. This example maps an old flag name ('old-flag-name') to a new one ('new-flag-name'), ensuring they are treated interchangeably.
```go
func aliasNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
case "old-flag-name":
name = "new-flag-name"
break
}
return pflag.NormalizedName(name)
}
myFlagSet.SetNormalizeFunc(aliasNormalizeFunc)
```
--------------------------------
### Check if started by Explorer (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/inconshreveable/mousetrap/README.md
This function checks if the current process was invoked by a user double-clicking the executable file in Windows Explorer. It returns a boolean value indicating the result. This is useful for providing more user-friendly behavior for CLI tools on Windows.
```Go
func StartedByExplorer() (bool)
```
--------------------------------
### Install Noti for macOS using curl and GitHub Releases
Source: https://github.com/variadico/noti/blob/main/README.md
Downloads and extracts the latest Noti binary for macOS (amd64 architecture) directly from GitHub releases using curl. This method is useful for users who prefer not to use a package manager.
```shell
# macOS install with curl
curl -L $(curl -s https://api.github.com/repos/variadico/noti/releases/latest | awk '/browser_download_url/ { print $2 }' | grep 'darwin-amd64' | sed 's/"//g') | tar -xz
```
--------------------------------
### Register and Use Aliases in Viper (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Explains how to create aliases for configuration keys, allowing a single configuration value to be accessed using multiple key names.
```Go
viper.RegisterAlias("loud", "Verbose")
vIper.Set("verbose", true) // same result as next line
vIper.Set("loud", true) // same result as prior line
vIper.GetBool("loud") // true
vIper.GetBool("verbose") // true
```
--------------------------------
### Enable Go Modules
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/TROUBLESHOOTING.md
This command enables Go Modules, which is the recommended way to manage dependencies for Go projects like noti. It helps resolve package not found errors that can occur when mixing GOPATH and Go Modules.
```bash
export GO111MODULE=on
```
--------------------------------
### Fetch Configuration from Consul with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Illustrates how to retrieve configuration from Consul's key/value store. This involves specifying the Consul address and the key containing the configuration. Requires the `viper/remote` package.
```go
viper.AddRemoteProvider("consul", "localhost:8500", "MY_CONSUL_KEY")
viper.SetConfigType("json")
err := viper.ReadRemoteConfig()
fmt.Println(viper.Get("port"))
fmt.Println(viper.Get("hostname"))
```
--------------------------------
### Unmarshal TOML to Go Struct
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Demonstrates how to use the `toml.Unmarshal` function to parse a TOML formatted string into a Go struct. It includes error handling and prints the unmarshaled struct's fields. The example assumes a `MyConfig` struct is defined.
```go
type MyConfig struct {
Version int
Name string
Tags []string
}
doc := `
version = 2
name = "go-toml"
tags = ["go", "toml"]
`
var cfg MyConfig
err := toml.Unmarshal([]byte(doc), &cfg)
if err != nil {
panic(err)
}
fmt.Println("version:", cfg.Version)
fmt.Println("name:", cfg.Name)
fmt.Println("tags:", cfg.Tags)
```
--------------------------------
### Help for tomll Tool (Shell)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Displays the help message for the tomll command-line tool. This shows available options and usage instructions for linting and reformatting TOML files.
```shell
tomll --help
```
--------------------------------
### Custom Flag Name Normalization (Separator Replacement)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/pflag/README.md
Shows how to define a custom normalization function for flag names. This example replaces hyphens and underscores with dots, allowing flags like --my-flag, --my_flag, and --my.flag to be treated as equivalent.
```go
func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName {
from := []string{"-", "_"}
to := "."
for _, sep := range from {
name = strings.Replace(name, sep, to, -1)
}
return pflag.NormalizedName(name)
}
myFlagSet.SetNormalizeFunc(wordSepNormalizeFunc)
```
--------------------------------
### Help for jsontoml Tool (Shell)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Displays the help message for the jsontoml command-line tool. This shows available options and usage instructions for converting JSON to TOML.
```shell
jsontoml --help
```
--------------------------------
### Read Configuration from io.Reader with Viper (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Demonstrates reading configuration data directly from an io.Reader, such as a byte buffer. This allows for custom configuration sources or configurations embedded within the application.
```Go
viper.SetConfigType("yaml") // or viper.SetConfigType("YAML")
// any approach to require this configuration into your program.
var yamlExample = []byte(`
Hacker: true
name: steve
hobbies:
- skateboarding
- snowboarding
- go
clothing:
jacket: leather
trousers: denim
age: 35
eyes : brown
beard: true
`)
vIper.ReadConfig(bytes.NewBuffer(yamlExample))
vIper.Get("name") // this would be "steve"
```
--------------------------------
### Fetch Configuration from NATS with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Demonstrates fetching configuration from a NATS message broker using Viper. This requires the NATS endpoint and the subject/queue name for the configuration.
```go
viper.AddRemoteProvider("nats", "nats://127.0.0.1:4222", "myapp.config")
viper.SetConfigType("json")
err := viper.ReadRemoteConfig()
```
--------------------------------
### Run go-toml Tests
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/CONTRIBUTING.md
Command to execute all tests for the go-toml project using Go's built-in testing tool. Includes the race detector for identifying data races.
```bash
go test -race ./...
```
--------------------------------
### Run Go Benchmarks
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/CONTRIBUTING.md
Execute Go's built-in benchmark system to test performance. The '-count=10' flag runs each benchmark multiple times to account for system noise. This command is crucial for verifying performance changes.
```bash
go test ./... -bench=. -count=10
```
--------------------------------
### Bind a Set of pflags to Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Illustrates binding an entire collection of pflags, such as the command line flags, to Viper. This enables unified configuration management.
```go
pflag.Int("flagname", 1234, "help message for flagname")
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
i := viper.GetInt("flagname") // retrieve values from viper instead of pflag
```
--------------------------------
### Import Cobra in Go Application
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/cobra/README.md
Demonstrates how to import the Cobra library into a Go project.
```go
import "github.com/spf13/cobra"
```
--------------------------------
### Run Benchmark Tests (Shell)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Executes benchmark tests for the go-toml library using a provided script. The flags '-a' and '-html' likely enable all benchmarks and generate HTML output respectively.
```shell
./ci.sh benchmark -a -html
```
--------------------------------
### Set Overrides in Viper (Go)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Shows how to programmatically set configuration values, which can be used to override values from configuration files or set application-specific parameters.
```Go
viper.Set("Verbose", true)
vIper.Set("LogFile", LogFile)
vIper.Set("host.port", 5899) // set subset
```
--------------------------------
### Afero Utility Functions Signature
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/afero/README.md
Lists the available utility functions in Afero, including their signatures and return types. These functions abstract underlying file system operations.
```go
DirExists(path string) (bool, error)
Exists(path string) (bool, error)
FileContainsBytes(filename string, subslice []byte) (bool, error)
GetTempDir(subPath string) string
IsDir(path string) (bool, error)
IsEmpty(path string) (bool, error)
ReadDir(dirname string) ([]os.FileInfo, error)
ReadFile(filename string) ([]byte, error)
SafeWriteReader(path string, r io.Reader) (err error)
TempDir(dir, prefix string) (name string, err error)
TempFile(dir, prefix string) (f File, err error)
Walk(root string, walkFn filepath.WalkFunc) error
WriteFile(filename string, data []byte, perm os.FileMode) error
WriteReader(path string, r io.Reader) (err error)
```
--------------------------------
### Print Help (Shell)
Source: https://github.com/variadico/noti/blob/main/docs/noti.md
Displays the help message for the 'noti' command, listing all available options and their descriptions, using the '-h' or '--help' flag.
```shell
-h, --help
```
--------------------------------
### Noti CLI Usage
Source: https://github.com/variadico/noti/blob/main/docs/noti.md
Provides information on how to run the Noti CLI tool and its basic synopsis.
```APIDOC
## Noti CLI Usage
### Description
This section describes the basic command-line usage for the Noti tool, including its synopsis and general purpose.
### Method
CLI Command
### Endpoint
N/A
### Parameters
#### Path Parameters
- **utility** (string) - Required - The utility command or script to monitor.
- **args** (string) - Optional - Arguments to pass to the utility command.
#### Query Parameters
None
#### Request Body
None
### Request Example
```sh
noti [flags] [utility [args...]]
```
### Response
#### Success Response (0)
- **Output**: Standard output of the monitored utility.
- **Notification**: A notification is triggered upon completion of the utility.
#### Response Example
(No specific response body for the CLI command itself, but notifications are sent based on the flags used.)
```
--------------------------------
### Fetch Encrypted Configuration from etcd with Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Illustrates how to securely fetch encrypted configuration from etcd using Viper's `AddSecureRemoteProvider`. It requires the etcd endpoint, config path, and a GPG keyring path for decryption.
```go
viper.AddSecureRemoteProvider("etcd","http://127.0.0.1:4001","/config/hugo.json","/etc/secrets/mykeyring.gpg")
viper.SetConfigType("json")
err := viper.ReadRemoteConfig()
```
--------------------------------
### Set Environment Variable Prefix and Bind
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Demonstrates setting an environment variable prefix and binding a key to an environment variable. The prefix is automatically uppercased. Environment variables are typically set outside the application.
```go
SetEnvPrefix("spf") // will be uppercased automatically
BindEnv("id")
os.Setenv("SPF_ID", "13") // typically done outside of the app
id := Get("id") // 13
```
--------------------------------
### Bind Individual pflag to Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Shows how to bind a single pflag, typically defined for a command, to a Viper key. This allows configuration values to be read through Viper.
```go
serverCmd.Flags().Int("port", 1138, "Port to run Application server on")
viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))
```
--------------------------------
### Run Viper Linters with Make
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Runs linters on the Viper project code using the 'make lint' command. The '-j' option can be used to parallelize the linter execution for faster checks.
```shell
make lint # pass -j option to run them in parallel
```
--------------------------------
### Integrate Standard Library Flags with pflag and Viper
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/spf13/viper/README.md
Demonstrates how to incorporate flags defined using Go's standard library `flag` package into Viper by first adding them to a pflag.FlagSet. This allows Viper to manage both standard and pflag-defined flags.
```go
package main
import (
"flag"
"github.com/spf13/pflag"
)
func main() {
// using standard library "flag" package
flag.Int("flagname", 1234, "help message for flagname")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
i := viper.GetInt("flagname") // retrieve value from viper
// ...
}
```
--------------------------------
### Run all tests
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/fsnotify/fsnotify/CONTRIBUTING.md
Executes all tests within the project. The CI system uses this command to run tests across all supported platforms. For faster testing, the `-short` flag can be used to speed up the 'stress test'.
```bash
go test ./...
```
--------------------------------
### Help for tomljson Tool (Shell)
Source: https://github.com/variadico/noti/blob/main/vendor/github.com/pelletier/go-toml/v2/README.md
Displays the help message for the tomljson command-line tool. This shows available options and usage instructions for converting TOML to JSON.
```shell
tomljson --help
```