Skip to content
/ cmd Public template

A kit-starter template to create internal cli's πŸ’»

License

Notifications You must be signed in to change notification settings

muxit-studio/cmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

cmd

Simple command line interface template for creating internal CLI's πŸ’»

Structure

β”œβ”€β”€ cmd
β”‚Β Β  └── {cmd_name}
β”‚Β Β      └── main.go
β”œβ”€β”€ {cmd_name}.go
β”œβ”€β”€ {cmd_sub_name}.go
β”œβ”€β”€ ...
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ LICENSE
β”œβ”€β”€ Makefile
└── README.md

The layout consists on the pkg directory which has all the dependencies that I need for creating custom CLI's and the cmd directory which just executes the cmd package which is all the {cmd_name}.go, {cmd_sub_name}.go files...

The config pkg works as a getter and setter of json, where you can config.Query() and config.Set() on a specific config path.

conf := c.Conf{
  Id:   "{cmd_name}",
  Dir:  "{configs_path}",
  File: "config.json",
}

Check https://github.com/thedevsaddam/gojsonq

How do I use this?

  1. Clone, fork it as a template
  2. Do make init and add your command name
  3. go mod download

How do I have shell completion?

Put this snippet on your .bashrc or any file that is integrated to the .bashrc (sourced in some way).

Note: change your_cmd to the name of your executable.

#!/usr/bin/env bash

if [[ -x "$(command -v your_cmd)" ]]; then
  _cli_bash_autocomplete() {
    if [[ "${COMP_WORDS[0]}" != "source" ]]; then
      local cur opts
      COMPREPLY=()
      cur="${COMP_WORDS[COMP_CWORD]}"
      if [[ "$cur" == "-"* ]]; then
        opts=$("${COMP_WORDS[@]:0:$COMP_CWORD}" "${cur}" --generate-bash-completion)
      else
        opts=$("${COMP_WORDS[@]:0:$COMP_CWORD}" --generate-bash-completion)
      fi
      COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
      return 0
    fi
  }

  complete -o nospace -F _cli_bash_autocomplete your_cmd
fi

About

A kit-starter template to create internal cli's πŸ’»

Resources

License

Stars

Watchers

Forks

Packages

No packages published