cmdx

package
v0.0.0-...-419c0c3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path       string         `json:"path,omitempty"`
	Args       jsonx.Strings  `json:"args,omitempty"`
	Env        jsonx.Strings  `json:"env,omitempty"`
	InheritEnv bool           `json:"inherit_env,omitempty"`
	Dir        string         `json:"dir,omitempty"`
	Log        LogConfig      `json:"log"`
	Restart    RestartConfig  `json:"restart"`
	WaitDelay  jsonx.Duration `json:"wait_delay,omitempty"`
}

type LogConfig

type LogConfig logConfig

func (LogConfig) MarshalJSON

func (p LogConfig) MarshalJSON() ([]byte, error)

func (*LogConfig) Open

func (p *LogConfig) Open() (stdout *os.File, stderr *os.File, closeIt func(), err error)

func (*LogConfig) UnmarshalJSON

func (p *LogConfig) UnmarshalJSON(data []byte) (err error)

type Option

type Option func(*Program)

func Log

func Log(logger *slog.Logger) Option

func Prepare

func Prepare(onPrepare func(p *Config) error) Option

func ProcessInline

func ProcessInline(processInline func(s string, stdout bool)) Option

type Program

type Program struct {
	// contains filtered or unexported fields
}

func Start

func Start(ctx context.Context, options ...Option) *Program

Start 启动一个程序并返回Program实例

参数:

  • ctx: 控制程序生命周期的context上下文
  • options: 配置程序的各种选项,如日志、准备回调等

返回值: 返回Program指针,可用于控制程序启停

func (*Program) Done

func (s *Program) Done() <-chan struct{}

取得退出信号

func (*Program) Restart

func (s *Program) Restart() error

重启

func (*Program) Start

func (s *Program) Start() error

启动

func (*Program) Status

func (s *Program) Status() string

取得状态

func (*Program) Stop

func (s *Program) Stop() error

停止

type RestartConfig

type RestartConfig restartConfig

func (RestartConfig) CheckWait

func (p RestartConfig) CheckWait(ctx context.Context, stop_ctx context.Context, count int, err error) (restart bool)

func (RestartConfig) MarshalJSON

func (p RestartConfig) MarshalJSON() ([]byte, error)

func (*RestartConfig) UnmarshalJSON

func (p *RestartConfig) UnmarshalJSON(data []byte) (err error)

Jump to

Keyboard shortcuts

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