Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrIsHelp = errors.New("argument is help message")
)
Functions ¶
This section is empty.
Types ¶
type DisableLiveUpdate ¶ added in v0.3.1
type DisableLiveUpdate struct{}
DisableLiveUpdate implements LiveUpdateOpt
type EnableLiveUpdate ¶ added in v0.3.1
type EnableLiveUpdate struct{}
EnableLiveUpdate implements LiveUpdateOpt
type File ¶ added in v0.3.1
type File[T any, L LiveUpdateOpt] struct { // contains filtered or unexported fields }
Load T from configuration file File[T, L] can be used with scli argument parser, or separately To enable live update, use File[T, scli.EnableLiveUpdate] To disable live update, use File[T, scli.DisableLiveUpdate]
func (*File[T, L]) Example ¶ added in v0.3.1
Example returns an example of config-file input Marker for Parse
func (*File[T, L]) FromString ¶ added in v0.3.1
Parse data from file
func (*File[T, L]) Get ¶ added in v0.3.1
func (f *File[T, L]) Get() *T
Get() returns the inner T instance
func (*File[T, L]) UpdateEvents ¶ added in v0.3.1
UpdateEvents() returns a channel of fsnotify.Events. An event will be send to this channel once the file changes.
type LiveUpdateOpt ¶ added in v0.3.1
type LiveUpdateOpt interface {
// contains filtered or unexported methods
}
LiveUpdateOpt is type restriction of L in File[T, L]. EnableLiveUpdate and DisableLiveUpdate are two types implemented LiveUpdateOpt. This interface SHOULD NOT be implemented by users.
type MarkOnce ¶ added in v0.3.1
type MarkOnce[T Parse] struct { // contains filtered or unexported fields }
EXPERIMENTAL: MarkOnce[T]: convert Parse to ParseOnce for type T that *T is Parse
struct {
t T
}
should now define:
type TOnce = scli.MarkOnce[*T]
struct {
tOnce TOnce
}
and get T by call tOnce.Get()
func (*MarkOnce[T]) FromString ¶ added in v0.3.1
type Parse ¶
Parse is the interface for custom type. Any type implemented this interface can be used as an argument/option in scli's definition struct.
type ParseOnce ¶ added in v0.3.1
type ParseOnce interface {
Parse
// contains filtered or unexported methods
}
ParseOnce is an interface for types that are Parse, but the FromString() of the type should be called at most once. This restriction is vital for implementing types like ConfigFile. Lets see why. First, some definitions.
Definitions:
1. Stateful Assuming all the outside running environment is unchanged, for instance t, calling t.FromString() once and calling t.FromString(..) for the second time will result in different behavior. One example is FromString contains logics based on a global variable which is inherited next time, then the second call will not trigger the same logic.
2. Impure For instance t, the result of t.FromString(..) not only dependent on the code of FromString it self, and may produce different outcome based on the running environment. One example is FromString read a file, and file may or may not exist on different environment.
For ConfigFile type, apparently, it's Impure because it relies on files which is not part of the code. For ConfigFile that can live update it's value when file is changed, the type is Stateful. A watcher is created for the first time a FromString() success and when file changes, FromString is called again to load new data, but not creating new watchers.
For ParseOnce, scli will not check default value nor example value, and Parser.Parse()FromString is called only once at parsing. If you think your type T is ParseOnce, use MarkOnce[T] to convert your Parse type to ParseOnce
type Parser ¶
type Parser[T any] struct { // contains filtered or unexported fields }