marshal

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package marshal provides a representation of the command line model in a serializable data model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisallowUnknownFields added in v0.14.1

func DisallowUnknownFields() codec.Option

DisallowUnknownFields affects unmarshaling and prevents unknown fields from being specified.

func From

func From(v any, opts ...Option) any

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 RegisterCodec added in v0.14.1

func RegisterCodec(c Codec, f func() codec.Interface)

RegisterCodec provides the behavior of registering a codec. This is expected to be called by implementations in their package initializer

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"`
}

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"`
}

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"
const (
	JSON Codec = iota
	YAML
	TOML
)

func (Codec) Available added in v0.14.1

func (c Codec) Available() bool

Available indicates whether the codec type is registered

func (Codec) New added in v0.14.1

func (c Codec) New(opts ...codec.Option) (codec.Interface, error)

New creates an instance of the given codec

func (Codec) String added in v0.14.1

func (c Codec) String() string

String provides the name of the codec

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"`
}

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"`
}

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

type Type

type Type int

Type identifies the built-in supported types

const (
	UnknownType Type = 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 (Type) MarshalText

func (t Type) MarshalText() ([]byte, error)

MarshalText provides the textual representation

func (Type) New

func (t Type) New() any

func (*Type) Set

func (t *Type) Set(arg string) error

func (Type) String

func (t Type) String() string

func (*Type) UnmarshalText

func (t *Type) UnmarshalText(b []byte) error

UnmarshalText converts the textual representation

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.

Jump to

Keyboard shortcuts

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