devscripts

package module
v0.0.57 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 7 Imported by: 0

README

DevScripts Package

Project Badges

scripts commonly used by a developer in his daily workflow

Available Scripts

This section is automatically generated.

Script Name Description Usage
autoBackup.sh Performs backup operations using FreeFileSync on Windows systems ./autoBackup.sh
badges.sh Generate SVG badges for GitHub projects and update README Example: badges.sh "license:MIT:#007acc" "go:1.22:#00add8" "coverage:85%:#28a745"
changeremote.sh Script to change the remote URL of a Git repository ./changeremote.sh https://github.com/username/repository.git
delete.sh Script to delete a file locally and track the deletion in Git ./delete.sh filename.txt
fileIssues.sh Functions to work with issues.md file usage: source fileIssues.sh
functions.sh Helper functions for git and script execution management source functions.sh
githubutils.sh Utility functions for GitHub repository management and user information retrieval source githubutils.sh
gitremtracking.sh Removes files from git tracking both locally and remotely ./gitremtracking.sh file1.txt file2.txt
gitutils.sh Git utilities for repository initialization and management source gitutils.sh && init_new_repo "my-project" "github.com/username"
goaddtest.sh Script to generate Go test files with unit test and benchmark templates ./goaddtest.sh CreateFile create
gobadge.sh Determine Go project badges and generate them using badges.sh gobadge.sh <module_name> <test_status> <coverage_percent> <race_status> <vet_status> [license_type]
goget.sh Updates a Go package to its latest tagged version ./goget.sh package-name
gomodcheck.sh Checks and updates Go module dependencies, runs tests and performs data race detection ./gomodcheck.sh
gomodinit.sh Script to initialize a Go module and create basic project structure ./gomodinit.sh
gomodrename.sh Rename a Go module and update all its references ./gomodrename.sh old-module-name new-module-name
gomodtagupdate.sh Updates Go module versions across all projects that use them ./gomodtagupdate.sh <package-name> <new-version>
gomodutils.sh Utility functions for managing Go modules and version updates source gomodutils.sh && update_single_go_module "mymodule" "v1.2.3"
gonewproject.sh Creates a new Go project with standard directory structure and initial files, sets up remote repository ./gonewproject.sh <repo-name> <description> [visibility]
gopkgupdate.sh Updates Go packages in go.mod to their latest versions from local repositories ./gopkgupdate.sh
gopu.sh Automated workflow for Go projects: checks modules, updates dependencies, creates tags, backs up and pushes to remote gopu.sh "Commit message"
gorenameproject.sh Script to rename a Go project and update its module references ./gorenameproject.sh old-project-name new-project-name
gotest.sh Run Go tests, vet, race detection and coverage analysis gotest.sh [project_directory]
goupgrade.sh Updates Go packages and tidies up module dependencies ./goupgrade.sh
issue.sh Script to manage GitHub issues using functions.sh helpers `./issue.sh [args] eg: []./issue.sh + "My issue" bug]
license.sh Detect license type from LICENSE files license.sh
licensecreate.sh Create and commit a license file for a Git repository ./licensecreate.sh [license-type] [owner-name]
mdutils.sh README.md utility functions for updating sections dynamically ./mdutils.sh section_identifier [after_line] new_content [readme_file]
parentdir.sh Gets the parent directory of the script's location source parentdir.sh parentDir=$(get_parent_dir)
pu.sh Script to commit changes, create a new tag, and push to remote ./pu.sh "Commit message"
rename.sh Rename a file and update Git tracking ./rename.sh <current_name> <new_name>
repocreate.sh Creates a new GitHub repository with initial README and license files `./repocreate.sh my-repo "My description" [public
repodelete.sh Deletes a remote GitHub repository after confirmation and permission checks ./repodelete.sh <repo-name> [force_delete] [owner]
repoexistingsetup.sh Setup additional files and tags for an existing Git repository ./repoexistingsetup.sh
repolocalinit.sh Initialize a new local Git repository with basic files and remote setup ./repolocalinit.sh
reporename.sh Renames a repository both locally and on remote GitHub, updates Git remotes ./reporename.sh <old-name> <new-name>
syscall.sh Check if a Go package uses syscall/js imports ./syscall.sh <package_name>
tag.sh Script to automatically increment the last number in a Git tag ./tag.sh (will get the latest tag and suggest the next one)
tagalldelete.sh Bulk delete git tags listed in a text file ./tagalldelete.sh <filename>
tagallrename.sh Mass rename multiple git tags using a file ./tagallrename.sh <filename>
tagdelete.sh Delete git tags locally and remotely tagdelete.sh tag1 tag2 tag3
taggo.sh Updates the version tag of a Go module in go.mod file ./taggo.sh <package_name>
tagrename.sh Rename git tags both locally and remotely ./tagrename.sh <old_tag> <new_tag>
tags.sh Lists git tags with their commit messages, sorted by date ./tags.sh
tagver.sh Compare local and remote git tag versions ./tagver.sh
testScript.sh A test script to demonstrate gorunscript functionality ./testScript.sh [error]
vpssetupbase.sh Base VPS setup for Debian-based Linux servers sudo ./vpssetupbase.sh <username> <ssh_key>
vpssetupsecurity.sh VPS security setup script for Debian-based Linux servers sudo ./vpssetupsecurity.sh <username> <new_ssh_port>

Use with Go

This package provides functionality for executing different types of scripts with Go in a consistent way across different operating systems.

ScriptRunner

The ScriptRunner handles the execution of scripts with appropriate interpreters based on file extensions.

Basic Usage
import "path/to/devscripts"

// Create a new script runner with default directory (current working directory)
runner := devscripts.NewScriptRunner()

// Or with a specific scripts directory
runner := devscripts.NewScriptRunner("/path/to/scripts")

// Execute a script with arguments
exitCode, output, err := runner.ExecScript("myscript.sh", "arg1", "arg2")
if err != nil {
    // Handle error
    fmt.Printf("Script execution failed: %v\n", err)
    return
}

fmt.Printf("Script executed with exit code %d\n", exitCode)
fmt.Printf("Output:\n%s\n", output)
Chained Script Execution

The package supports chained script execution, where scripts run sequentially and execution stops if any script fails:

// Create a script chain
exitCode, output, err := runner.Chain().
    Then("script1.sh", "arg1").
    Then("script2.py", "arg2", "arg3").
    Then("script3.sh").
    Execute()

if err != nil {
    fmt.Printf("Chain execution failed: %v\n", err)
    return
}

fmt.Printf("All scripts executed successfully with combined output:\n%s\n", output)
Accessing Individual Results

You can also access the results of the last executed script in a chain:

chain := runner.Chain().
    Then("script1.sh").
    Then("script2.sh")

// Execute the chain
chain.Execute()

// Access results
exitCode := chain.ExitCode()
output := chain.Output()
err := chain.Error()

fmt.Printf("Last script exit code: %d\n", exitCode)
fmt.Printf("Last script output: %s\n", output)
if err != nil {
    fmt.Printf("Last script error: %v\n", err)
}

Supported Script Types

By default, the following script types are supported:

  • Shell scripts (.sh) - executed with bash
  • Python scripts (.py) - executed with python

On Windows, Git Bash is used for executing shell scripts.


Contributing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBackticks added in v0.0.47

func AddBackticks(s string) string

Helper formatters that can be used with SetColumnFormatter

func BuildMarkdownTable added in v0.0.47

func BuildMarkdownTable(scripts []ScriptInfo) string

BuildMarkdownTable creates a markdown table from script info using the MdTable API This function provides backward compatibility and a simple interface for common use cases

func ExecuteWithArgs added in v0.0.47

func ExecuteWithArgs(fn func(...string))

ExecuteWithArgs ejecuta una función después de cambiar al directorio especificado El primer argumento siempre debe ser el directorio de trabajo Los argumentos restantes se pasan a la función

func GetExtraArgs added in v0.0.47

func GetExtraArgs() []string

GetExtraArgs retorna los argumentos adicionales (después del directorio)

func GetWorkingDirectory added in v0.0.47

func GetWorkingDirectory() string

GetWorkingDirectory retorna el directorio de trabajo del primer argumento

func NewScriptRunner

func NewScriptRunner(scriptsDir ...string) *scriptRunner

NewScriptRunner creates a handler for scripts using an optional scripts directory parameter. If no directory is provided, it uses the current working directory.

func SectionUpdate added in v0.0.47

func SectionUpdate(args ...string)

MdUtils is the main function that follows the established pattern

func TrimHashPrefix added in v0.0.47

func TrimHashPrefix(s string) string

Types

type DevScriptsReadmeUpdater added in v0.0.47

type DevScriptsReadmeUpdater struct {
	// contains filtered or unexported fields
}

DevScriptsReadmeUpdater handles updating README.md with scripts documentation

func NewDevScriptsReadmeUpdater added in v0.0.47

func NewDevScriptsReadmeUpdater(scriptsDir string) *DevScriptsReadmeUpdater

NewDevScriptsReadmeUpdater creates a new DevScriptsReadmeUpdater

func (*DevScriptsReadmeUpdater) GenerateScriptsSection added in v0.0.47

func (dru *DevScriptsReadmeUpdater) GenerateScriptsSection() (string, error)

GenerateScriptsSection generates a markdown section for README with scripts table

func (*DevScriptsReadmeUpdater) UpdateReadme added in v0.0.47

func (dru *DevScriptsReadmeUpdater) UpdateReadme(readmePath string) error

UpdateReadme updates the README file with the scripts section using sectionUpdate

func (*DevScriptsReadmeUpdater) UpdateReadmeIfNeeded added in v0.0.47

func (dru *DevScriptsReadmeUpdater) UpdateReadmeIfNeeded(readmePath string) (bool, error)

UpdateReadmeIfNeeded updates README and returns true if changes were made

type Devbashscripts

type Devbashscripts struct{}

func New

func New() *Devbashscripts

type MdHandler added in v0.0.47

type MdHandler struct {
	// contains filtered or unexported fields
}

func NewMdHandler added in v0.0.47

func NewMdHandler(args ...string) *MdHandler

func (*MdHandler) SectionUpdate added in v0.0.47

func (h *MdHandler) SectionUpdate() error

SectionUpdate updates or creates a section in README based on identifier

type MdTable added in v0.0.47

type MdTable struct {
	// contains filtered or unexported fields
}

MdTable handles creation of markdown tables

func NewMdTable added in v0.0.47

func NewMdTable(headers []string) *MdTable

NewMdTable creates a new MdTable with headers

func (*MdTable) AddRow added in v0.0.47

func (mt *MdTable) AddRow(row []string)

AddRow adds a row to the table

func (*MdTable) Generate added in v0.0.47

func (mt *MdTable) Generate() string

Generate creates the markdown table string

func (*MdTable) SetColumnFormatter added in v0.0.47

func (mt *MdTable) SetColumnFormatter(colIndex int, formatter func(string) string)

SetColumnFormatter sets a formatter function for a column (0-based index)

func (*MdTable) SetEmptyPlaceholder added in v0.0.47

func (mt *MdTable) SetEmptyPlaceholder(colIndex int, placeholder string)

SetEmptyPlaceholder sets placeholder text for empty cells in a column (0-based index)

func (*MdTable) SetMaxColumnWidth added in v0.0.47

func (mt *MdTable) SetMaxColumnWidth(colIndex, width int)

SetMaxColumnWidth sets maximum width for a column (0-based index)

func (*MdTable) SetMinColumnWidth added in v0.0.47

func (mt *MdTable) SetMinColumnWidth(colIndex, width int)

SetMinColumnWidth sets minimum width for a column (0-based index)

func (*MdTable) SetRows added in v0.0.47

func (mt *MdTable) SetRows(rows [][]string)

SetRows sets all rows at once

type ScriptChain added in v0.0.4

type ScriptChain struct {
	// contains filtered or unexported fields
}

ScriptChain represents a chain of scripts to be executed in sequence

func (*ScriptChain) Error added in v0.0.4

func (sc *ScriptChain) Error() error

Error returns the error of the last executed script

func (*ScriptChain) Execute added in v0.0.4

func (sc *ScriptChain) Execute() (int, string, error)

Execute runs all scripts in the chain until one fails

func (*ScriptChain) ExitCode added in v0.0.4

func (sc *ScriptChain) ExitCode() int

ExitCode returns the exit code of the last executed script

func (*ScriptChain) Output added in v0.0.4

func (sc *ScriptChain) Output() string

Output returns the output of the last executed script

func (*ScriptChain) Then added in v0.0.4

func (sc *ScriptChain) Then(scriptName string, args ...string) *ScriptChain

Then adds a script to the execution chain

type ScriptInfo added in v0.0.47

type ScriptInfo struct {
	Name        string
	Description string
	Usage       string
}

ScriptInfo represents information about a shell script

type ScriptParser added in v0.0.47

type ScriptParser struct {
	// contains filtered or unexported fields
}

ScriptParser handles parsing of shell scripts

func NewScriptParser added in v0.0.47

func NewScriptParser(scriptsDir string) *ScriptParser

NewScriptParser creates a new ScriptParser

func (*ScriptParser) GetScriptNames added in v0.0.47

func (sp *ScriptParser) GetScriptNames() ([]string, error)

GetScriptNames obtiene los nombres de los scripts .sh en el directorio

func (*ScriptParser) ParseScripts added in v0.0.47

func (sp *ScriptParser) ParseScripts() ([]ScriptInfo, error)

ParseScripts obtiene las descripciones de los scripts

Jump to

Keyboard shortcuts

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