Docli - Command-line interfaces made easy

Related tags

Command Line docli
Overview

Docli

Docli

Build Status GoDoc All Contributors

Docli is a declarative language for describing command-line interfaces in Go programs. It cuts down the boilerplate to the bare minimum, so you can move on to the reason why you’re making the app in the first place.

Docli is 100% inspired by docopt.

Contributors

Thanks goes to these wonderful people:

riot
riot

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Issues
  • Let's talk about the next release

    Let's talk about the next release

    Super Docli

    The next release will be the version 2.0.0. I want to push the development of the subcommands feature due to the most significant feedback I've received:

    Docli should allow nested commands, what's the point otherwise?

    Quite frankly, I agree! Docli can't compete with other Go libraries at the same level because of this significant disadvantage.

    The current API 👎

    Docli was designed to allow embedded structs to provide a way to group related arguments and create abstractions like commands and flags:

    package main
    
    import (
    	"log"
    
    	"github.com/celicoo/docli"
    )
    
    var doc = `
    Usage: terraform [--version] [--help] <command> [args]
    
    ...
    
    Common commands:
        apply              Builds or changes infrastructure
        console            Interactive console for Terraform interpolations
    `
    
    type Terraform struct {
    	CommonCommands
    }
    
    type CommonCommands struct {
    	Apply,
    	Console bool
    }
    
    func main() {
    	args, err := docli.Parse(doc)
    	if err != nil {
    		log.Fatal(err)
    	}
    
    	var terraform Terraform
    	args.Bind(&terraform)
    
    	if terraform.CommonCommands.Apply {
    		// ...
    	} else if terraform.CommonCommands.Console {
    		// ...
    	}
    }
    

    The problems with this approach are obvious now:

    • The program's complexity grows proportionally to the number of arguments, making it harder to test, maintain and even understand it.
    • Misplaced responsibility - validation and parsing errors return on the same call
    • Weird API - docli.Parse(doc string) (Args, error)

    The new API 👍

    The new API aims to solve the problems pointed above, add the subcommands feature.

    1st change: the function Parse(doc string) (Args, error) is going to be replaced with the function Args() Args:

    var c MyCommand
    args := docli.Args()
    args.Bind(&c)
    

    The second returning value (error) is going to be removed. See 2nd and 3rd changes to understand the reason.

    2nd change: the struct passed to Bind will need to implement the Command interface:

    type command interface {
    	// Doc returns the docstring of a command.
    	Doc() string
    	// Run is called when the fields of a command are bound with matching
    	// command-line arguments.
    	Run()
    	// Help is called when a user runs "<command> help".
    	Help()
    	// Error is called when unregistered command-line arguments are passed.
    	Error(error)
    }
    

    3rd change: parsing errors will panic.

    But wait, what about the subcommands feature?

    The concrete command type can have fields that are themselves concrete Commands. You can check a simple example here if you didn't get it.

    Feedback

    Please don't hesitate to comment on this Issue. I will love to know your thoughts about the changes that are coming.

    feedback:discussion feedback:rfc 
    opened by celicoo 4
  • docs: add mention to Golang

    docs: add mention to Golang

    Changed the documentation to let readers know this project is for Go programs.

    Checklist:

    • [ ] I have added tests to cover my changes
    • [ ] All new and existing tests passed
    • [ ] My change requires a change to the documentation
    • [X] I have updated the documentation accordingly
    improvement:enhancement 
    opened by ri0t 3
  • Runtime default values

    Runtime default values

    This is more of a question, rather than issue.

    In the following example (from your repo)

    var doc = `
    Usage:	docker [OPTIONS] COMMAND
    
    A self-sufficient runtime for containers
    
    Options:
          --config string      Location of client config files (default "/Users/celicoo/.docker")
    `
    

    the default "/Users/celicoo/.docker" is set at compile time.

    What if I need the default to depend on the user's environment, something like

    var doc = `
    Usage:	docker [OPTIONS] COMMAND
    
    A self-sufficient runtime for containers
    
    Options:
          --config string      Location of client config files (default "$HOME/.docker")
    `
    

    Currently, what I'm thinking of doing is string replacement

    home := os.Getenv("HOME")
    
    var doc = `
    Usage:	docker [OPTIONS] COMMAND
    
    A self-sufficient runtime for containers
    
    Options:
          --config string      Location of client config files (default "%s/.docker")
    `
    
    doc := strings.Replace(doc, home)
    

    Any thoughts ?

    feedback:question 
    opened by jbrodriguez 2
  • Website seems to be dead?

    Website seems to be dead?

    Description

    Can't seem to resolve docli.dev anymore.

    Expected behavior

    docli.dev works.

    Actual behavior

    docli.dev doesn't resolve ** server can't find docli.dev: SERVFAIL

    Possible Fix

    Your environment

    • Version used:
    • Link to your project:
    mindless:chore 
    opened by viveklak 2
  • docs: add mention to Golang

    docs: add mention to Golang

    ..to avoid confusion.

    Checklist:

    • [ ] I have added tests to cover my changes
    • [ ] All new and existing tests passed
    • [ ] My change requires a change to the documentation
    • [X] I have updated the documentation accordingly
    inactive:duplicate inactive:invalid pending:in progress 
    opened by ri0t 1
  • feat: release of v2.0.0

    feat: release of v2.0.0

    Super Docli

    After 3 months of development, I'm glad to announce that v2.0.0 is ready to go!

    Checklist:

    • [x] I have added tests to cover my changes
    • [x] All new and existing tests passed
    • [x] My change requires a change to the documentation
    • [x] I have updated the documentation accordingly

    Closes #10

    addition:feature improvement:enhancement improvement:optimization 
    opened by celicoo 0
Owner
Marcelo Franco Filipe Alves
Obsessed to learn all things, but focused mainly in tech
Marcelo Franco Filipe Alves
Go binding configuration and command flag made easy✨✨

✨ Binding configuration and command flag made easy! ✨ You can use multiple keys tag to simplify the look like this (supported feature**): // single ta

Ii64人 13 Mar 2, 2022
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Clement Sam 2k Jun 25, 2022
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

null 0 Nov 22, 2021
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Venky 0 Dec 22, 2021
Simple and easy to use command line application written in Go for cleaning unnecessary XCode files.

xcclear Say hello to a few extra gigabytes of space on your Mac with xcclear, a simple and easy to use command line application written in Go for clea

null 57 Jun 28, 2022
Portal is a quick and easy command-line file transfer utility from any computer to another 🖥️ 🌌 💻

Portal is a quick and easy command-line file transfer utility from any computer to another ??️ ?? ??

Zino Kader 146 Jul 1, 2022
Package varflag implements command-line flag parsing into vars.Variables for easy type handling with additional flag types.

varflag Package flag implements command-line flag parsing into vars.Variables for easy type handling with additional flag types. varflag Flags String

Marko Kungla 2 Feb 11, 2022
Git Add Commit - Commit made easy

Git Add Commit Commit made easy Installation Download the latest release and put the binary in your $PATH Homebrew: brew tap rawnly/tap brew i

Federico Vitale 2 Dec 16, 2021
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Rohit Gupta 2k Jun 23, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Gruntwork 599 Jun 26, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Maxar Infrastructure 1 Feb 5, 2022
Package command provide simple API to create modern command-line interface

Package command Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra Usage pack

chenen 0 Jan 16, 2022
A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Moh Achun Armando 0 Dec 18, 2021
Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Geet Sethi 1 Mar 27, 2022
A command launcher 🚀 made with ❤️

Command Launcher A command launcher ?? made with ❤️ Why a command launcher? At Criteo, we have many teams who provides command line applications for d

Criteo 3 May 30, 2022
A go library for easy configure and run command chains. Such like pipelining in unix shells.

go-command-chain A go library for easy configure and run command chains. Such like pipelining in unix shells. Example cat log_file.txt | grep error |

null 24 May 30, 2022
It is an easy and fast tool to install your packages with just one command.

Trouxa It is an easy and fast tool to install your packages with just one command. What means "Trouxa"? In portuguese, Trouxa means something like a "

Baianoware 7 Feb 13, 2022
LINE account link: Sample code for LINE account link

LINE account link: Sample code for LINE account link This is sample code to demostration LINE chatbot account link, refer to document https://develope

null 0 Dec 11, 2021
argv - Go library to split command line string as arguments array using the bash syntax.

Argv Argv is a library for Go to split command line string into arguments array. Documentation Documentation can be found at Godoc Example func TestAr

null 33 May 7, 2022