cmd

package
v0.0.0-...-4d173fc Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2025 Daniel Rivas <danielrivasmd@gmail.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const DateYMD = "2006-01-02"

date format

Variables

This section is empty.

Functions

func Assign

func Assign(field string, holder any, v any)

Assign sets any null.* wrapper (null.String, null.Int64, null.Bool, null.Time) into a named field.

func AssignBool

func AssignBool(field string, holder any, v any)

AssignBool sets a bool into a named field.

func AssignDate

func AssignDate(field string, holder any, v any)

AssignDate sets a time.Time into a named field (for NOT NULL date/time columns).

func AssignInt64

func AssignInt64(field string, holder any, v any)

AssignInt64 sets an int64 into a named field (e.g., FK task).

func AssignNullableDate

func AssignNullableDate(field string, holder any, v any)

AssignNullableDate sets a null.Time into a named field (for nullable dates).

func AssignString

func AssignString(field string, holder any, v any)

AssignString sets a plain string into a named field.

func AttachEditCompletion

func AttachEditCompletion[T any](
	cmd *cobra.Command,
	listFn func(ctx context.Context, db *sql.DB) ([]T, error),
	format func(item T) (int64, string),
	hintFn func(item T) string,
)

func AttachRmCompletion

func AttachRmCompletion[T any](
	cmd *cobra.Command,
	listFn func(ctx context.Context, db *sql.DB) ([]T, error),
	format func(item T) (int64, string),
	hintFn func(item T) string,
)

func EnsureDB

func EnsureDB() error

TODO: needed ensuredb? EnsureDB open the DB using the same logic as dbPreRun reuse that here so __complete has a live connection

func Execute

func Execute()

func OptInt64Initial

func OptInt64Initial(v null.Int64) string

func OptStringInitial

func OptStringInitial(v null.String) string

func OptTimeInitial

func OptTimeInitial(v null.Time, layout string) string

func ParseBool

func ParseBool(s string) (any, error)

ParseBool supports true/false/1/0/yes/no; returns bool.

func ParseDate

func ParseDate(s string) (any, error)

ParseDate parses a required date (YYYY-MM-DD) into time.Time.

func ParseInt64

func ParseInt64(s string) (any, error)

ParseInt64 parses a required int64.

func ParseNonEmpty

func ParseNonEmpty(label string) func(string) (any, error)

ParseNonEmpty returns the string if non-empty; else error.

func ParseOptDate

func ParseOptDate(s string) (any, error)

ParseOptDate parses an optional date (YYYY-MM-DD) into null.Time.

func ParseOptInt64

func ParseOptInt64(s string) (any, error)

ParseOptInt64 parses an optional int64 into null.Int64.

func ParseOptString

func ParseOptString(s string) (any, error)

ParseOptString converts free text into null.String (blank → Valid:true, String:"").

func RegisterCrudSubcommands

func RegisterCrudSubcommands[T any](
	parent *cobra.Command,
	dbPath string,
	desc CrudModel[T],
)

func RenderTable

func RenderTable(headers []string, rows [][]string) string

func RunFormWizard

func RunFormWizard(fields []Field, holder any)

func RunFormWizardWithSubmit

func RunFormWizardWithSubmit(fields []Field, holder any, onSubmit func(holder any) error)

func VBool

func VBool(label string) func(string) error

VBool validates a free-form boolean (true/false/1/0/yes/no).

func VDate

func VDate(label string) func(string) error

VDate enforces a required YYYY-MM-DD date (for NOT NULL time.Time).

func VDateOptional

func VDateOptional() func(string) error

VDateOptional validates optional YYYY-MM-DD date (for null.Time).

func VIntRange

func VIntRange(min, max int64) func(string) error

VIntRange validates optional integer input within [min, max]. Blank passes (use with optional fields). Pair with ParseOptInt64.

func VRequired

func VRequired(label string) func(string) error

VRequired enforces non-empty input.

Types

type CrudModel

type CrudModel[T any] struct {
	Singular     string
	ListFn       func(ctx context.Context, db *sql.DB) ([]T, error)
	RemoveFn     func(ctx context.Context, db *sql.DB, id int64) error
	Format       func(item T) (int64, string)
	TableHeaders []string
	TableRow     func(item T) []string
	HintFn       func(item T) string
}

TODO: add verbose option

type Field

type Field struct {
	Name     string
	Label    string
	Initial  string
	Validate func(input string) error

	Parse  func(string) (any, error)
	Assign func(holder any, v any)
	Input  textinput.Model
	// contains filtered or unexported fields
}

func FBool

func FBool(label, field, initial string) Field

FBool builds a boolean field (plain bool). If your model uses null.Bool, wrap with null.BoolFrom in Assign.

func FChoice

func FChoice(label string, initial string, allow []string, setter func(string)) Field

func FDate

func FDate(label, field, initial string, opts ...FieldOpt) Field

FDate builds a required date field (time.Time).

func FInt

func FInt(label, field, initial string, opts ...FieldOpt) Field

FInt builds a required int64 field.

func FOptDate

func FOptDate(label, field, initial string, opts ...FieldOpt) Field

FOptDate builds an optional date field (null.Time).

func FOptInt

func FOptInt(label, field, initial string, opts ...FieldOpt) Field

FOptInt builds an optional int64 field (null.Int64).

func FOptString

func FOptString(label, field, initial string, opts ...FieldOpt) Field

FOptString remains optional; add opts for consistency.

func FString

func FString(label, field, initial string, opts ...FieldOpt) Field

FString builds a required non-empty string field.

type FieldOpt

type FieldOpt func(*Field)

func WithAssign

func WithAssign(a func(any, any)) FieldOpt

func WithInitial

func WithInitial(s string) FieldOpt

func WithLabel

func WithLabel(lbl string) FieldOpt

func WithParse

func WithParse(p func(string) (any, error)) FieldOpt

func WithValidate

func WithValidate(v func(string) error) FieldOpt

type FormModel

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

func NewFormModel

func NewFormModel(fields []Field, holder any) FormModel

func (FormModel) Init

func (m FormModel) Init() tea.Cmd

func (FormModel) Update

func (m FormModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (FormModel) View

func (m FormModel) View() string

Jump to

Keyboard shortcuts

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