structedit

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Structedit

Package structedit allows to interactively edit structure values.

It it basically a wrapper around survey library that parses the structure tags and generates necessary "questions".

Usage example:

package main

import (
	"fmt"
	"log"

	"github.com/rusq/structedit"
)

type testStruct struct {
	StrFoo     string `ed:"Foo:that's a foo"`
	IntBar     int    `ed:"Bar:enter a bar value"`
	Bool       bool   `ed:"bool:enter a boolean value"`
	SkipMe     string `ed:"-:this should be skipped"`
	OmitMe     int64  `ed:",omitempty:this should be skipped when zero"`
	FloatNoTag float32
	unexported string `ed:"unexported:this should not be visible"`
}

func main() {
	var x testStruct

	print(x)

	ed := structedit.New()
	if err := ed.Ask("sample", &x); err != nil {
		log.Fatal(err)
	}
	print(x)
}

func print(a any) {
	fmt.Printf("%#v\n", a)
}

Documentation

Overview

Package structedit allows to interactively edit structure values.

It it basically a wrapper around survey library that parses the structure tags and generates necessary "questions".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ask

func Ask(msg string, a any) error

Types

type Editor

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

func New

func New(opt ...Option) *Editor

func (*Editor) Ask

func (ed *Editor) Ask(msg string, a any) error

type Option

type Option func(*Editor)

func WithOKLabel

func WithOKLabel(label, description string) Option

func WithSeparator

func WithSeparator(sep string) Option

func WithTag

func WithTag(tag string) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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