Documentation
¶
Overview ¶
Package marshal provides a representation of the command line model in a serializable data model.
Index ¶
- Variables
- func ContextValue(v *CodecProvider) cli.Action
- func DisallowUnknownFields() codec.Option
- func Dump(v ...any) cli.Action
- func DumpContext(ctx context.Context, v ...any) error
- func EscapeHTML() codec.Option
- func From(v any, opts ...Option) any
- func ListCodecs() cli.Action
- func RegisterCodec(c Codec, f func() codec.Interface)
- func SetOutput(v ...Codec) cli.Action
- func SetOutputArgument(v ...Codec) cli.Action
- func WithIndent(indent string) codec.Option
- type App
- type Arg
- type BuiltinType
- type Codec
- type CodecProvider
- func (c *CodecProvider) Apply(opts ...CodecProviderOption)
- func (c *CodecProvider) Codec() codec.Interface
- func (c *CodecProvider) MarshalWrite(w io.Writer, in any) error
- func (c *CodecProvider) Pipeline() cli.Action
- func (c *CodecProvider) SetCodec(in codec.Interface)
- func (c *CodecProvider) UnmarshalRead(r io.Reader, out any) error
- type CodecProviderOption
- type Command
- type Flag
- type Option
- type Options
- type Schema
- type Type
Constants ¶
This section is empty.
Variables ¶
var CodecRegistry = &provider.Registry{
Name: "codec",
Providers: codecLookup{},
}
CodecRegistry provides a provider.Registry that enumerates the supported codecs. Each codec is instanced from a factory that takes Options as its argument, and only codecs which have been registered are listed. Use ListCodecs to expose the registry via a flag.
Functions ¶
func ContextValue ¶ added in v0.18.0
func ContextValue(v *CodecProvider) cli.Action
ContextValue provides an action that sets the given value into the context. The only supported type is *CodecProvider.
func DisallowUnknownFields ¶ added in v0.14.1
DisallowUnknownFields affects unmarshaling and prevents unknown fields from being specified.
func Dump ¶ added in v0.18.0
Dump provides an action which dumps out the specified values to stdout using the codec in the context. See DumpContext.
func DumpContext ¶ added in v0.18.0
DumpContext prints the specified values to stdout. If the context provides the CLI context, then the stdout writer specified by it will be used; otherwise, os.Stdout will be used. The codec to use will be retrieved from the context; however, as a special case, if the first value is itself is a codec.Interface (or merely implements its MarshalWrite method), this specifies the codec to use rather than the one in the context. New lines separate each item.
func EscapeHTML ¶ added in v0.18.0
EscapeHTML affects marshaling and generates escaped HTML within JSON. For other codecs, this option generates an error.
func From ¶
From creates the schema serialization value for the given Joe value. The following types are supported:
- *cli.App
- *cli.Arg
- *cli.Command
- *cli.Flag
Any other type of value specified will panic
func ListCodecs ¶ added in v0.18.0
ListCodecs provides an action that lists the supported codecs then exits. This action only works if the Registry has been installed into the context; otherwise, it produces an error
func RegisterCodec ¶ added in v0.14.1
RegisterCodec provides the behavior of registering a codec. This is expected to be called by implementations in their package initializer
func SetOutputArgument ¶ added in v0.18.0
SetOutputArgument provides a flag which sets an argument on the codec uses for dumping
func WithIndent ¶ added in v0.18.0
WithIndent affects marshaling and sets the string used for each level of indentation in the encoded output.
Types ¶
type App ¶
type App struct {
Name string `json:"name"`
Commands []Command `json:"commands,omitempty"`
Flags []Flag `json:"flags,omitempty"`
Args []Arg `json:"args,omitempty"`
HelpText string `json:"helpText,omitempty"`
ManualText string `json:"manualText,omitempty"`
UsageText string `json:"usageText,omitempty"`
Version string `json:"version,omitempty"`
BuildDate time.Time `json:"buildDate"`
Author string `json:"author,omitempty"`
Copyright string `json:"copyright,omitempty"`
License string `json:"license,omitempty"`
Comment string `json:"comment,omitempty"`
Options Options `json:"options,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
App provides a representation of cli.App for use as data
type Arg ¶
type Arg struct {
Name string `json:"name"`
EnvVars []string `json:"envVars,omitempty"`
FilePath string `json:"filePath,omitempty"`
HelpText string `json:"helpText,omitempty"`
ManualText string `json:"manualText,omitempty"`
Category string `json:"category,omitempty"`
UsageText string `json:"usageText,omitempty"`
DefaultText string `json:"defaultText,omitempty"`
Options Options `json:"options,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
Arg provides a representation of cli.Arg for use as data
type BuiltinType ¶ added in v0.17.0
type BuiltinType int
BuiltinType identifies the built-in supported types
const ( UnknownType BuiltinType = iota BigFloat BigInt Bool Bytes Duration File FileSet Float32 Float64 Int Int16 Int32 Int64 Int8 IP List Map NameValue NameValues Regexp String Uint Uint16 Uint32 Uint64 Uint8 URL )
The various types that the CLI supports
func (BuiltinType) MarshalText ¶ added in v0.17.0
func (t BuiltinType) MarshalText() ([]byte, error)
MarshalText provides the textual representation
func (BuiltinType) New ¶ added in v0.17.0
func (t BuiltinType) New() any
func (*BuiltinType) Set ¶ added in v0.17.0
func (t *BuiltinType) Set(arg string) error
func (BuiltinType) String ¶ added in v0.17.0
func (t BuiltinType) String() string
func (*BuiltinType) UnmarshalText ¶ added in v0.17.0
func (t *BuiltinType) UnmarshalText(b []byte) error
UnmarshalText converts the textual representation
type Codec ¶ added in v0.14.1
type Codec int
Codec identifies the support codecs. The JSON codec is supported by default. To add support for additional codecs, you must import them or register them. For example,
import _ "github.com/Carbonfrost/joe-cli/extensions/marshal/codec/toml"
type CodecProvider ¶ added in v0.18.0
CodecProvider provides the context-bound provider that can be used as a codec.
func CodecProviderFromContext ¶ added in v0.18.0
func CodecProviderFromContext(ctx context.Context) *CodecProvider
CodecProviderFromContext retrieves the codec provider from the context
func NewCodecProvider ¶ added in v0.18.0
func NewCodecProvider(opts ...CodecProviderOption) *CodecProvider
NewCodecProvider provides a value that provides the codec to use when dumping. By default, adding the provider to the pipeline adds it as a context service which facilitates configuring the codec used by Dump
func (*CodecProvider) Apply ¶ added in v0.18.0
func (c *CodecProvider) Apply(opts ...CodecProviderOption)
Apply will apply the given options to the provider
func (*CodecProvider) Codec ¶ added in v0.18.0
func (c *CodecProvider) Codec() codec.Interface
Codec gets the codec used internally by the provider
func (*CodecProvider) MarshalWrite ¶ added in v0.18.0
func (c *CodecProvider) MarshalWrite(w io.Writer, in any) error
MarshalWrite provides marshaling by delegating to the internal codec if it exists. JSON is used by default
func (*CodecProvider) Pipeline ¶ added in v0.18.0
func (c *CodecProvider) Pipeline() cli.Action
func (*CodecProvider) SetCodec ¶ added in v0.18.0
func (c *CodecProvider) SetCodec(in codec.Interface)
SetCodec sets the codec used internally by the provider
func (*CodecProvider) UnmarshalRead ¶ added in v0.18.0
func (c *CodecProvider) UnmarshalRead(r io.Reader, out any) error
UnmarshalRead provides unmarshaling by delegating to the internal codec if it exists. JSON is used by default
type CodecProviderOption ¶ added in v0.18.0
type CodecProviderOption func(*CodecProvider)
CodecProviderOption provides options for the provider
func WithAction ¶ added in v0.18.0
func WithAction(a cli.Action) CodecProviderOption
WithAction sets the action to use with the codec
func WithDefaultAction ¶ added in v0.18.0
func WithDefaultAction() CodecProviderOption
WithDefaultAction sets the action to the default, which sets the CodecProvider into the context and sets up the flags: SetOutput, SetOutputArgument, and ListCodecs
type Command ¶
type Command struct {
Name string `json:"name"`
Aliases []string `json:"aliases,omitempty"`
Subcommands []Command `json:"subcommands,omitempty"`
Flags []Flag `json:"flags,omitempty"`
Args []Arg `json:"args,omitempty"`
HelpText string `json:"helpText,omitempty"`
ManualText string `json:"manualText,omitempty"`
UsageText string `json:"usageText,omitempty"`
Comment string `json:"comment,omitempty"`
Category string `json:"category,omitempty"`
Options Options `json:"options,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
Command provides a representation of cli.Command for use as data
type Flag ¶
type Flag struct {
Name string `json:"name"`
Aliases []string `json:"aliases,omitempty"`
EnvVars []string `json:"envVars,omitempty"`
FilePath string `json:"filePath,omitempty"`
HelpText string `json:"helpText,omitempty"`
ManualText string `json:"manualText,omitempty"`
Category string `json:"category,omitempty"`
UsageText string `json:"usageText,omitempty"`
DefaultText string `json:"defaultText,omitempty"`
Options Options `json:"options,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
Flag provides a representation of cli.Flag for use as data
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies an option for creating marshal values
func WithPrivateData ¶ added in v0.10.0
func WithPrivateData() Option
WithPrivateData provides an option that causes private data, which is any data added to a Data map whose key starts with understcore, is included in the marshal representation of a target. By default, private data is excluded
type Options ¶ added in v0.10.0
type Options = cli.Option
Options provides a representation of cli.Option for use as data
type Schema ¶ added in v0.17.0
Schema represents a structural type with named fields
func (Schema) MarshalJSON ¶ added in v0.17.0
MarshalJSON provides JSON representation of the schema
func (Schema) MarshalText ¶ added in v0.17.0
MarshalText provides the textual representation
func (*Schema) UnmarshalJSON ¶ added in v0.17.0
UnmarshalJSON parses JSON representation into a schema
Directories
¶
| Path | Synopsis |
|---|---|
|
Package codec provides a model and conventions for marshaling and unmarshaling values to and from their encodings.
|
Package codec provides a model and conventions for marshaling and unmarshaling values to and from their encodings. |
|
toml
Package toml provides the TOML codec
|
Package toml provides the TOML codec |