questionnaire

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 6 Imported by: 0

README

Config Questionnaire

GitHub LicenseGitHub Top LanguageGitHub Actions StatusGo Report CardCoverage Status

A Go module for dynamically generating and running questionnaires based on the struct fields of provided config models.

Overview

This module leverages reflection to inspect struct fields of any given config model and generates a questionnaire accordingly. It supports fields of type string, int (and its variants), and bool. The questionnaire is interactive and runs in the terminal using the huh library for form generation and input handling.

Installation

To use this module in your Go project, ensure you have Go 1.22.1 or later, then run:

go get github.com/STRockefeller/config-questionnaire

Usage

  1. Define a config model as a Go struct. You can use the questionnaire tag to customize the field name in the questionnaire.
package example

type Example struct {
	Name   string `questionnaire:"title:What's your name;"`
	Age    int
	HasPet bool
}
  1. Use the GenerateAndRunQuestionnaire function to generate and run the questionnaire based on your model.
package main

import (
    "fmt"
    questionnaire "github.com/STRockefeller/config-questionnaire"
    "github.com/STRockefeller/config-questionnaire/example"
)

func main() {
    e, err := questionnaire.GenerateAndRunQuestionnaire[example.Example]()
    if err != nil {
        panic(err)
    }
    fmt.Println(e)
}
  1. the generated questionnaire will be run in the terminal and the user will be prompted to enter values for each field. The values will be returned as a struct of the same type as the model.

example

Dependencies

This module relies on several external libraries for its functionality:

License

This module is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateAndRunQuestionnaire

func GenerateAndRunQuestionnaire[configModel any]() (configModel, error)

GenerateAndRunQuestionnaire dynamically creates and runs a questionnaire based on the struct fields of the provided model.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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