argoparser

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 3 Imported by: 0

README

Argparse for Go

Installation

go get github.com/carter499/argoparser

Usage

Import
import ap "github.com/carter499/argoparser"
Example
package main

import (
	"fmt"
	ap "gitbub.com/carter4299/argoparser"
)

func main() {
	parser := ap.NewArgParser("This is a sample command-line tool.")

	fname := parser.AddArgument("i", "input", true, "Input file")
	fsize := parser.AddFloatArgument("s", "size", false, "Size of the file")
	verbose := parser.AddBoolArgument("v", "verbose", false, "Enable verbose output")
	age := parser.AddIntArgument("a", "age", true, "Your age")

	err := parser.Parse()
	if err != nil {
		fmt.Println(err)
		return
	}

	if *verbose {
		fmt.Println("Verbose mode is enabled.")
	}

	fmt.Printf("Input file: %s\n", *fname)
	fmt.Printf("File size: %f\n", *fsize)
	fmt.Printf("Hello! You are %d years old.\n", *age)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgParser

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

func NewArgParser

func NewArgParser(desc string) *ArgParser

func (*ArgParser) AddArgument

func (ap *ArgParser) AddArgument(short, long string, required bool, help string) *string

func (*ArgParser) AddBoolArgument

func (ap *ArgParser) AddBoolArgument(short, long string, defaultValue bool, help string) *bool

func (*ArgParser) AddFloatArgument

func (ap *ArgParser) AddFloatArgument(short, long string, required bool, help string) *float64

func (*ArgParser) AddIntArgument

func (ap *ArgParser) AddIntArgument(short, long string, required bool, help string) *int

func (*ArgParser) Parse

func (ap *ArgParser) Parse() error

func (*ArgParser) PrintHelp

func (ap *ArgParser) PrintHelp()

Jump to

Keyboard shortcuts

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