/switchterm

This is a cli tool to generate go functions, bash, go servers. It also allows you to tag these and search them.

Primary LanguageGoGNU Affero General Public License v3.0AGPL-3.0

switchterm

Alt text

GitHub repo file count GitHub code size in bytes GitHub repo size GitHub GitHub commit activity Go 100% status beta Website shields.ioPRs WelcomeMaintenanceGitHub go.mod Go version of a Go moduleGoDoc reference exampleGoReportCard examplesaythanks

General info

This project is a command line selection tool. It stores commands in a sqlite database and their tags

Why build this?

  • Go never changes
  • Wanted a easy quick way to run commands and search for them.

What does it do?

  • Made a multi-part series on it
  • part2

Change the directory of the commands and run them

Alt text

You can even do search by tag

Alt text

Run multiple commands

Alt text

Make bash files and run arguments in them

Alt text

Generate your server

Alt text

Generate your get handlers

Alt text

Generate your data and choose the Handler you want it to be connected to

Alt text

Technologies

Project is created with:

Requirements

  • go 1.21 for gonew

How to run as is?

*- clone it

git clone https://github.com/golangast/switchterm
    • or
    • install gonew to pull down project quickly
go install golang.org/x/tools/cmd/gonew@latest
    • run gonew
gonew github.com/golangast/switchterm example.com/switchterm
    • cd into switchterm
cd switchterm
    • run the project
go run main.go

Repository overview

├── bash #where bash commands are generated
├── cmd  #where cmd commands are generated
├── db   #database for switchterm
├── loggers #loggers for switchterm
├── readmeimages #readmeimages for switchterm readme
├── switchtermer 
│   ├── cmd  #how cmd commands are generated
│   ├── data #data for switchterm (under construction)
│   ├── db   #database for switchterm
│   ├── generate  #generate switchterm
│   ├── settings  #settings for switchterm
│   ├── switch    #main switch fuctions
│   └── window    #window for switch

Overview of the code.

  1. allows for the user to select one from multiple values
answer := DigSingle(lists, 1, "green", "red")
  1. allows for the user to select many from multiple values
answer := Dig(lists, 1, "green", "red")
  1. prints the selection and formats it.
switchutility.PrintColumnsWChosen(cols, atline, results, background, foreground)
  1. allows you to ask a question and save the value
       fmt.Println("add a commnd..")
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		inputcmd := scanner.Text()
  1. prints the directions and clears the terminal
 	switchutility.ClearDirections()
  1. allows you to start the keyboard key press selecting
         err := keyboard.Listen(func(key keys.Key) (stop bool, err error) {
		switch key.String() {

*improved library sugar syntax

  1. to display a list of values to be chosen
	domainanswer := switchselector.MenuInstuctions(ds, 1, "purple", "purple", "which domain do you prefer to use?")
  1. to ask a question and store the answer
    datafields := switchutility.InputScanDirections("Whats the fields of the data? ")
  1. to run bash commands to usually pull down imports.
if err := switchutility.ShellBash("cd genserv/ && go run ."); err != nil {
		switchutility.Checklogger(err, "running certification")
	}
  1. to update text in a file.
	if err := switchutility.UpdateText("dirtory/file.go", "text to check for", "what you are replacing", "text to do replacing"); err != nil {
		switchutility.Checklogger(err, "message for the error")
	}

Things to remember

  • using atomicgo.dev/keyboard there is no way to call itself after a key press
  • Remember to run the database server. It is under the generate command
  • If you are using digital ocean
    • Remember to generate certs
    • Remember to change their permissions sudo chmod 755 /etc/letsencrypt/live/yourdomain/*.pem # Adjust if file names differ
    • Remember to run the database in /bin
 ./rqlited -auth config.json -http-addr yourdomain.com:25060 -http-cert /etc/letsencrypt/live/yourdomain.com/fullchain.pem -http-key /etc/letsencrypt/live/yourdomain.com/privkey.pem  ~/node.1

Reference Commands

  • "enter" is to select
  • "c" is to select many
  • "r" is to remove
  • "x" is to execute
  • "q" is to quit

Just added

  • Just added to the genserv not the switchterm (did not add support for database https yet)
  • rqlite
  • gorqlite

Licenses

  1. GNU 3 for my code
  2. MIT License for atomicgo keyboard
  3. MIT License for sprig
  4. BSD-3-Clause for sqlite driver
  5. BSD-3-Clause for Go itself

Special thanks

Why Go?