cmd_impel

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GistApi     = "https://api.github.com/gists"
	PasteBinApi = "https://pastebin.com/api/api_post.php"
)

Variables

This section is empty.

Functions

func AddFromEditor

func AddFromEditor(name string, enable bool)

func AddFromFiles

func AddFromFiles(files []string, enable bool, keepFileName bool)

func DeleteSnippetsFromNames

func DeleteSnippetsFromNames(names []string)

func DeleteSnippetsFromSelect

func DeleteSnippetsFromSelect()

func DisableGormDebugging

func DisableGormDebugging()

func DisableSnippetsFromNames

func DisableSnippetsFromNames(names []string)

func DisableSnippetsFromSelect

func DisableSnippetsFromSelect()

func EnableSnippetsFromNames

func EnableSnippetsFromNames(names []string)

func EnableSnippetsFromSelect

func EnableSnippetsFromSelect()

func FoundSnippet

func FoundSnippet(name string) (r defines.ShellSnippet, e error)

func GetAllEnabledSnippet

func GetAllEnabledSnippet() (rs []defines.ShellSnippet, e error)

func GetAllSnippets

func GetAllSnippets() (rs []defines.ShellSnippet, err error)

func InitDB

func InitDB() error

func InitRC

func InitRC()

func ListAndPrint

func ListAndPrint()

func PrintTarget

func PrintTarget(r defines.ShellSnippet)

func SaveSnippet

func SaveSnippet(sn defines.ShellSnippet)

func SelectSnippet

func SelectSnippet() (r defines.ShellSnippet)

func SelectSnippets

func SelectSnippets() (rs []defines.ShellSnippet)

func SelectSnippetsReturnStringSlice

func SelectSnippetsReturnStringSlice() (rs []string)

Types

type GistFile added in v1.0.0

type GistFile struct {
	Content string `json:"content"`
}

type GistJson added in v1.0.0

type GistJson struct {
	Description string              `json:"description"`
	Public      bool                `json:"public"`
	Files       map[string]GistFile `json:"files"`
}

'{"description":"Example of a gist","public":false,"files":{"README.md":{"content":"Hello World"}}}'

type GistResponse added in v1.0.0

type GistResponse struct {
	Url string `json:"html_url"`
}

type PasteJson added in v1.0.0

type PasteJson struct {
	ApiDevKey      string `json:"api_dev_key" form:"api_dev_key"`
	ApiOption      string `json:"api_option" form:"api_option"`
	ApiPasteName   string `json:"api_paste_name" form:"api_paste_name"`
	ApiPasteCode   string `json:"api_paste_code" form:"api_paste_code"`
	ApiPasteFormat string `json:"api_paste_format" form:"api_paste_format"`
}

type ShareFunction added in v1.0.0

type ShareFunction func(t defines.ShellSnippet, secret string) (string, error)
var ShareOnGithub ShareFunction = func(t defines.ShellSnippet, s string) (string, error) {
	var gistR GistResponse
	r := gout.POST(GistApi).SetHeader(gout.H{
		"Accept":        "application/vnd.github+json",
		"Content-Type":  "application/json",
		"Authorization": "Bearer " + s,
	}).SetJSON(&GistJson{
		Description: "Shared by ShellScriptSnippet",
		Public:      true,
		Files: map[string]GistFile{
			fmt.Sprintf("%s.sh", strings.ReplaceAll(t.Name, " ", "_")): {t.Content},
		},
	}).BindJSON(&gistR).Debug()

	if log.GlobalLogLevel > log.LogLevelInfo {
		r.Debug(true)
	}

	e := r.Do()
	if e != nil {
		return "", e
	}
	return gistR.Url, nil
}
var ShareOnPastebin ShareFunction = func(t defines.ShellSnippet, s string) (string, error) {
	var str string
	r := gout.POST(PasteBinApi).SetForm(&PasteJson{
		ApiDevKey:      s,
		ApiOption:      "paste",
		ApiPasteCode:   t.Content,
		ApiPasteFormat: "bash",
		ApiPasteName:   t.Name,
	}).BindBody(&str)

	if log.GlobalLogLevel > log.LogLevelInfo {
		r.Debug(true)
	}

	e := r.Do()
	if e != nil {
		return "", e
	}
	if !strings.HasPrefix(str, "http") {
		return str, errors.New("bad request")
	}
	return str, nil
}

Jump to

Keyboard shortcuts

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