discord

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 19 Imported by: 0

README

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

Documentation

Index

Constants

View Source
const (
	DefaultPerms = 0600
)
View Source
const VERSION = "0.1.0"

Variables

This section is empty.

Functions

func App

func App() *cli.App

func Create

func Create(path string) error

func Editor

func Editor(path string) error

Editor opens a file with the default $EDITOR from the user system

func Exec

func Exec(command string) error

func Exists

func Exists(path string) bool

func FormData

func FormData() *formData

NewFormData creates a new FormData instance.

func Input

func Input(prompt string) string

func InputConfirm

func InputConfirm(prompt string) bool

func InsertLine

func InsertLine(path, newLine string) error

func InsertLineAtIndex

func InsertLineAtIndex(path, newLine string, index int) error

func List

func List(dir string) []string

List returns all files in a directory, same as `ls`

func Mkdir

func Mkdir(path string) error

func Open

func Open(path string) error

Open opens a file with the default open command from the user system

func Read

func Read(filePath string) (string, error)

Read retrieves content from a file

func ReadLines

func ReadLines(filePath string) ([]string, error)

ReadLines returns all lines from a file

func Remove

func Remove(path string) error

func RemoveAll

func RemoveAll(path string) error

rm -r

func Write

func Write(path string, text string) error

Write writes content to a file. It will overwrite to the file if it already exists and create the file if it does not.

func WriteAppend

func WriteAppend(path string, text string) error

WriteAppend writes content to a file. It will append to the file if it already exists and create the file if it does not.

Types

type Conf

type Conf struct {
	Id   string // usually application name
	Dir  string // usually os.UserConfigDir
	File string // usually config.yaml
}

func (Conf) Data

func (c Conf) Data() []byte

func (Conf) Del

func (c Conf) Del(key string) error

func (Conf) DirPath

func (c Conf) DirPath() string

func (Conf) Edit

func (c Conf) Edit() error

func (Conf) Init

func (c Conf) Init() error

func (Conf) OverWrite

func (c Conf) OverWrite(newconf any) error

func (Conf) Path

func (c Conf) Path() string

func (Conf) Print

func (c Conf) Print() error

func (Conf) Query

func (c Conf) Query(q string) string

Using github.com/thedevsaddam/gojsonq to query json files.

Wiki: https://github.com/thedevsaddam/gojsonq/wiki/Queries

func (Conf) QueryPrint

func (c Conf) QueryPrint(q string)

QueryPrint prints the output of Query.

func (Conf) Set

func (c Conf) Set(key string, val any) error

type DiscordMessage

type DiscordMessage struct {
	Content   string  `json:"content,omitempty"`
	Username  string  `json:"username,omitempty"`
	AvatarURL string  `json:"avatar_url,omitempty"`
	TTS       bool    `json:"tts,omitempty"`
	Embeds    []Embed `json:"embeds,omitempty"`
}

type Embed

type Embed struct {
	Title       string            `json:"title,omitempty"`
	Description string            `json:"description,omitempty"`
	URL         string            `json:"url,omitempty"`
	Color       int               `json:"color,omitempty"`
	Fields      []EmbedField      `json:"fields,omitempty"`
	Author      *EmbedAuthor      `json:"author,omitempty"`
	Footer      *EmbedFooter      `json:"footer,omitempty"`
	Image       map[string]string `json:"image,omitempty"`
	Thumbnail   map[string]string `json:"thumbnail,omitempty"`
	Timestamp   string            `json:"timestamp,omitempty"`
}

func (*Embed) EnforceLimits

func (e *Embed) EnforceLimits()

type EmbedAuthor

type EmbedAuthor struct {
	Name    string `json:"name,omitempty"`
	IconURL string `json:"icon_url,omitempty"`
	URL     string `json:"url,omitempty"`
}

type EmbedField

type EmbedField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline"`
}

type EmbedFooter

type EmbedFooter struct {
	Text    string `json:"text,omitempty"`
	IconURL string `json:"icon_url,omitempty"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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