Skip to content

Go package designed to parse strings into command-line arguments following the POSIX Shell Command Language.

License

Notifications You must be signed in to change notification settings

notwithering/argo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Argo

MIT License Go Report Card

Argo is a simple package designed to parse strings into command-line arguments following the POSIX Shell Command Language.

Example

// cli application
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"

	"github.com/notwithering/argo"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	for {
		fmt.Print(" > ")

		in, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println(err)
			return
		}
		in = strings.TrimSpace(in)

		args, incomplete := argo.Parse(in)
		if incomplete {
			fmt.Println("error: incomplete command")
			continue
		}

		// example output:
		// "go", "build", "-ldflags", "-s -w"
		fmt.Print("\"")
		fmt.Print(strings.Join(args, "\", \""))
		fmt.Println("\"")

		if len(args) > 0 {
			if args[0] == "exit" {
				return
			}
		}
	}
}

What does Argo mean?

Argument Go

About

Go package designed to parse strings into command-line arguments following the POSIX Shell Command Language.

Topics

Resources

License

Stars

Watchers

Forks

Languages