help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
go-cli-tool
RSK World
go-cli-tool
Go CLI Tool v3.0 - Command-Line Interface with File Operations + Text Processing + System Monitoring + Cryptographic Tools + Network Utilities + HTTP Client + Image Processing + Cross-Platform Support + Modern Go Development
go-cli-tool
  • internal
  • LICENSE1.1 KB
  • README.md3.8 KB
  • RELEASE_NOTES_v3.0.md7 KB
  • demo-readme.md3 KB
  • go.mod403 B
  • index.html19.7 KB
  • main.go15.3 KB
  • test-commands.bat2.5 KB
  • test-commands.sh2.5 KB
main.go
main.go
Raw Download
Find: Go to:
/*
 * Project: Go CLI Tool
 * Category: Go Projects
 * Description: Command-line interface tool built with Go. Features file operations, text processing, command parsing, and system utilities.
 * Author: RSK World
 * Email: support@rskworld.in
 * Website: https://rskworld.in/contact.php
 * Year: 2026
 * Copyright (c) 2026 RSK World. All rights reserved.
 */

package main

import (
	"flag"
	"fmt"
	"net/url"
	"os"
	"path/filepath"
	"strconv"
	"strings"

	"go-cli-tool/internal/archive"
	"go-cli-tool/internal/conv"
	"go-cli-tool/internal/crypto"
	"go-cli-tool/internal/fileops"
	"go-cli-tool/internal/imgops"
	"go-cli-tool/internal/jsonops"
	"go-cli-tool/internal/monops"
	"go-cli-tool/internal/netops"
	"go-cli-tool/internal/random"
	"go-cli-tool/internal/sysutils"
	"go-cli-tool/internal/textproc"
	"go-cli-tool/internal/ui"
	"go-cli-tool/internal/utils"
	"go-cli-tool/internal/web"
)

// Validation functions
func validateFilePath(path string) bool {
	if path == "" {
		return false
	}
	// Check for dangerous characters
	dangerous := []string{"..", "<", ">", "|", "*", "?"}
	for _, char := range dangerous {
		if strings.Contains(path, char) {
			return false
		}
	}
	return true
}

func validateURL(rawURL string) bool {
	if rawURL == "" {
		return false
	}
	u, err := url.Parse(rawURL)
	return err == nil && u.Scheme != "" && u.Host != ""
}

func validatePositiveNumber(s string) bool {
	if s == "" {
		return false
	}
	num, err := strconv.Atoi(s)
	return err == nil && num > 0
}


func main() {
	if len(os.Args) < 2 {
		showPremiumHelp()
		os.Exit(1)
	}

	command := os.Args[1]

	switch command {
	// Core Operations
	case "file":
		handleFileCommand()
	case "text":
		handleTextCommand()
	case "sys":
		handleSysCommand()
	
	// Utility & Security
	case "net":
		handleNetCommand()
	case "crypto":
		handleCryptoCommand()
	case "archive":
		handleArchiveCommand()
	
	// Media & Data
	case "web":
		handleWebCommand()
	case "img":
		handleImgCommand()
	case "json":
		handleJsonCommand()
	
	// Advanced Tools
	case "rand":
		handleRandCommand()
	case "conv":
		handleConvCommand()
	case "mon":
		monops.ShowDashboard()
	case "shell":
		utils.StartInteractiveMode()
	
	case "help":
		showPremiumHelp()
	default:
		ui.Error(fmt.Sprintf("Unknown command: %s", command))
		fmt.Println("Type 'go-cli-tool help' for available commands.")
		os.Exit(1)
	}
}

func showPremiumHelp() {
	ui.Banner()
	
	ui.Header("CORE OPERATIONS")
	fmt.Println("  file    - File tasks (read, create, delete, list, copy, move, search, stats)")
	fmt.Println("  text    - Text processing (count, upper, lower, reverse, b64)")
	fmt.Println("  sys     - System utilities (info, time)")

	ui.Header("UTILITY & SECURITY")
	fmt.Println("  net     - Network tools (ip, dns)")
	fmt.Println("  crypto  - Security tools (hash)")
	fmt.Println("  archive - Archive management (zip, unzip)")

	ui.Header("MEDIA & DATA")
	fmt.Println("  web     - HTTP client (fetch, headers)")
	fmt.Println("  img     - Image utilities (info, convert)")
	fmt.Println("  json    - JSON tools (pretty, minify)")

	ui.Header("ADVANCED TOOLS")
	fmt.Println("  rand    - Random data (pass, uuid)")
	fmt.Println("  conv    - Unit converter (temp, weight, length, data)")
	fmt.Println("  mon     - Real-time system monitor dashboard")
	fmt.Println("  shell   - Launch interactive REPL mode")

	fmt.Printf("\n%sUsage:%s go-cli-tool <command> [subcommand] [args]\n", ui.Bold, ui.Reset)
}

func handleFileCommand() {
	fileCmd := flag.NewFlagSet("file", flag.ExitOnError)
	create := fileCmd.Bool("create", false, "Create a new file")
	read := fileCmd.Bool("read", false, "Read a file")
	delete := fileCmd.Bool("delete", false, "Delete a file")
	list := fileCmd.Bool("list", false, "List files in a directory")
	copy := fileCmd.Bool("copy", false, "Copy a file")
	move := fileCmd.Bool("move", false, "Move a file")
	search := fileCmd.Bool("search", false, "Search for text in files")
	stats := fileCmd.Bool("stats", false, "Get file statistics")
	name := fileCmd.String("name", "", "File name")
	dest := fileCmd.String("dest", "", "Destination filename (for copy/move)")
	content := fileCmd.String("content", "", "File content (for create)")
	dir := fileCmd.String("dir", ".", "Directory path (for list/search)")
	query := fileCmd.String("query", "", "Search query (for search)")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool file -name <filename> [-create -content <content> | -read | -delete | -stats]")
		fmt.Println("Usage: go-cli-tool file -list -dir <directory>")
		fmt.Println("Usage: go-cli-tool file -name <src> -dest <dst> [-copy | -move]")
		fmt.Println("Usage: go-cli-tool file -search -query <text> -dir <directory>")
		os.Exit(1)
	}

	fileCmd.Parse(os.Args[2:])

	if *create {
		if *name == "" {
			ui.Error("File name is required for creation")
			return
		}
		if !validateFilePath(*name) {
			ui.Error("Invalid file name provided")
			return
		}
		if err := fileops.CreateFile(*name, *content); err != nil {
			ui.Error(err.Error())
		}
	} else if *read {
		if *name == "" {
			ui.Error("File name is required for reading")
			return
		}
		if !validateFilePath(*name) {
			ui.Error("Invalid file name provided")
			return
		}
		if err := fileops.ReadFile(*name); err != nil {
			ui.Error(err.Error())
		}
	} else if *delete {
		if *name == "" {
			ui.Error("File name is required for deletion")
			return
		}
		if !validateFilePath(*name) {
			ui.Error("Invalid file name provided")
			return
		}
		if err := fileops.DeleteFile(*name); err != nil {
			ui.Error(err.Error())
		}
	} else if *list {
		if !validateFilePath(*dir) {
			ui.Error("Invalid directory path provided")
			return
		}
		if err := fileops.ListFiles(*dir); err != nil {
			ui.Error(err.Error())
		}
	} else if *copy {
		if *name == "" || *dest == "" {
			ui.Error("Source name and destination are required for copy")
			return
		}
		if !validateFilePath(*name) || !validateFilePath(*dest) {
			ui.Error("Invalid file paths provided")
			return
		}
		if err := fileops.CopyFile(*name, *dest); err != nil {
			ui.Error(err.Error())
		}
	} else if *move {
		if *name == "" || *dest == "" {
			ui.Error("Source name and destination are required for move")
			return
		}
		if !validateFilePath(*name) || !validateFilePath(*dest) {
			ui.Error("Invalid file paths provided")
			return
		}
		if err := fileops.MoveFile(*name, *dest); err != nil {
			ui.Error(err.Error())
		}
	} else if *search {
		if *query == "" {
			ui.Error("Search query is required")
			return
		}
		if !validateFilePath(*dir) {
			ui.Error("Invalid directory path provided")
			return
		}
		if err := fileops.SearchFiles(*dir, *query); err != nil {
			ui.Error(err.Error())
		}
	} else if *stats {
		if *name == "" {
			ui.Error("File name is required for stats")
			return
		}
		if !validateFilePath(*name) {
			ui.Error("Invalid file name provided")
			return
		}
		if err := fileops.GetFileStats(*name); err != nil {
			ui.Error(err.Error())
		}
	} else {
		ui.Error("No valid subcommand provided")
		fileCmd.Usage()
	}
}

func handleTextCommand() {
	textCmd := flag.NewFlagSet("text", flag.ExitOnError)
	count := textCmd.Bool("count", false, "Count words")
	upper := textCmd.Bool("upper", false, "Convert to uppercase")
	lower := textCmd.Bool("lower", false, "Convert to lowercase")
	reverse := textCmd.Bool("reverse", false, "Reverse text")
	encode := textCmd.Bool("encode", false, "Base64 encode")
	decode := textCmd.Bool("decode", false, "Base64 decode")
	input := textCmd.String("input", "", "Text input")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool text [-count | -upper | -lower | -reverse | -encode | -decode] -input \"text\"")
		os.Exit(1)
	}

	textCmd.Parse(os.Args[2:])

	if *input == "" {
		fmt.Println("Error: Input text is required")
		return
	}

	if *count {
		textproc.WordCount(*input)
	}
	if *upper {
		textproc.ToUpperCase(*input)
	}
	if *lower {
		textproc.ToLowerCase(*input)
	}
	if *reverse {
		textproc.ReverseText(*input)
	}
	if *encode {
		textproc.Base64Encode(*input)
	}
	if *decode {
		textproc.Base64Decode(*input)
	}
}

func handleSysCommand() {
	sysCmd := flag.NewFlagSet("sys", flag.ExitOnError)
	info := sysCmd.Bool("info", false, "Get system info")
	timeCmd := sysCmd.Bool("time", false, "Get current time")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool sys [-info | -time]")
		os.Exit(1)
	}

	sysCmd.Parse(os.Args[2:])

	if *info {
		sysutils.GetSystemInfo()
	} else if *timeCmd {
		sysutils.GetCurrentTime()
	} else {
		fmt.Println("Error: No valid subcommand provided")
		sysCmd.Usage()
	}
}

}
}

// ... (existing handlers)

func handleNetCommand() {
	netCmd := flag.NewFlagSet("net", flag.ExitOnError)
	ip := netCmd.Bool("ip", false, "Get local IP address")
	dns := netCmd.String("dns", "", "Lookup DNS for hostname")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool net [-ip | -dns <hostname>]")
		os.Exit(1)
	}

	netCmd.Parse(os.Args[2:])

	if *ip {
		netops.GetLocalIP()
	} else if *dns != "" {
		netops.LookupDNS(*dns)
	} else {
		fmt.Println("Error: No valid subcommand provided")
		netCmd.Usage()
	}
}

func handleCryptoCommand() {
	cryptoCmd := flag.NewFlagSet("crypto", flag.ExitOnError)
	hash := cryptoCmd.String("hash", "", "Generate SHA256 hash of text")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool crypto -hash \"text\"")
		os.Exit(1)
	}

	cryptoCmd.Parse(os.Args[2:])

	if *hash != "" {
		crypto.HashText(*hash)
	} else {
		fmt.Println("Error: Hash text is required")
		cryptoCmd.Usage()
	}
}

func handleArchiveCommand() {
	archiveCmd := flag.NewFlagSet("archive", flag.ExitOnError)
	zipCmd := archiveCmd.Bool("zip", false, "Zip a file or directory")
	unzipCmd := archiveCmd.Bool("unzip", false, "Unzip a file")
	source := archiveCmd.String("source", "", "Source file/dir")
	target := archiveCmd.String("target", "", "Target file/dir")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool archive -source <src> -target <dest> [-zip | -unzip]")
		os.Exit(1)
	}

	archiveCmd.Parse(os.Args[2:])

	if *source == "" || *target == "" {
		fmt.Println("Error: Source and target are required")
		return
	}

	if *zipCmd {
		if err := archive.ZipFile(*source, *target); err != nil {
			fmt.Println(err)
		}
	} else if *unzipCmd {
		if err := archive.UnzipFile(*source, *target); err != nil {
			fmt.Println(err)
		}
	} else {
		fmt.Println("Error: No valid subcommand provided")
		archiveCmd.Usage()
	}
}

func handleWebCommand() {
	webCmd := flag.NewFlagSet("web", flag.ExitOnError)
	fetch := webCmd.Bool("fetch", false, "Fetch URL content")
	headers := webCmd.Bool("headers", false, "Get URL headers")
	url := webCmd.String("url", "", "URL to fetch/inspect")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool web -url <url> [-fetch | -headers]")
		os.Exit(1)
	}

	webCmd.Parse(os.Args[2:])

	if *url == "" {
		ui.Error("URL is required")
		return
	}

	if !validateURL(*url) {
		ui.Error("Invalid URL format provided")
		return
	}

	if *fetch {
		web.FetchURL(*url)
	} else if *headers {
		web.GetHeaders(*url)
	} else {
		ui.Error("No valid subcommand provided")
		webCmd.Usage()
	}
}

func handleImgCommand() {
	imgCmd := flag.NewFlagSet("img", flag.ExitOnError)
	info := imgCmd.Bool("info", false, "Get image info")
	convert := imgCmd.Bool("convert", false, "Convert image to PNG")
	name := imgCmd.String("name", "", "Image file name")
	output := imgCmd.String("output", "", "Output file name (for convert)")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool img -info -name <filename>")
		fmt.Println("Usage: go-cli-tool img -convert -name <input> -output <output.png>")
		os.Exit(1)
	}

	imgCmd.Parse(os.Args[2:])

	if *info {
		if *name == "" {
			ui.Error("Image name is required")
			return
		}
		if !validateFilePath(*name) {
			ui.Error("Invalid image file path provided")
			return
		}
		imgops.GetImageInfo(*name)
	} else if *convert {
		if *name == "" || *output == "" {
			ui.Error("Input and output file names are required for conversion")
			return
		}
		if !validateFilePath(*name) || !validateFilePath(*output) {
			ui.Error("Invalid file paths provided")
			return
		}
		imgops.ConvertToPNG(*name, *output)
	} else {
		ui.Error("No valid subcommand provided")
		imgCmd.Usage()
	}
}

func handleJsonCommand() {
	jsonCmd := flag.NewFlagSet("json", flag.ExitOnError)
	pretty := jsonCmd.Bool("pretty", false, "Pretty print JSON")
	minify := jsonCmd.Bool("minify", false, "Minify JSON")
	name := jsonCmd.String("name", "", "JSON file name")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool json [-pretty | -minify] -name <filename>")
		os.Exit(1)
	}

	jsonCmd.Parse(os.Args[2:])

	if *name == "" {
		fmt.Println("Error: JSON file name is required")
		return
	}

	if *pretty {
		jsonops.PrettyPrint(*name)
	} else if *minify {
		jsonops.Minify(*name)
	} else {
		fmt.Println("Error: No valid subcommand provided")
		jsonCmd.Usage()
	}
}

func handleRandCommand() {
	randCmd := flag.NewFlagSet("rand", flag.ExitOnError)
	pass := randCmd.Bool("pass", false, "Generate random password")
	uuid := randCmd.Bool("uuid", false, "Generate random UUID")
	length := randCmd.Int("len", 16, "Password length")

	if len(os.Args) < 3 {
		fmt.Println("Usage: go-cli-tool rand [-pass -len <length> | -uuid]")
		os.Exit(1)
	}

	randCmd.Parse(os.Args[2:])

	if *pass {
		if *length < 4 || *length > 128 {
			ui.Error("Password length must be between 4 and 128 characters")
			return
		}
		random.GeneratePassword(*length)
	} else if *uuid {
		random.GenerateUUID()
	} else {
		ui.Error("No valid subcommand provided")
		randCmd.Usage()
	}
}

func handleConvCommand() {
	convCmd := flag.NewFlagSet("conv", flag.ExitOnError)
	val := convCmd.Float64("val", 0, "Value to convert")
	c2f := convCmd.Bool("c2f", false, "Celsius to Fahrenheit")
	f2c := convCmd.Bool("f2c", false, "Fahrenheit to Celsius")
	m2ft := convCmd.Bool("m2ft", false, "Meters to Feet")
	ft2m := convCmd.Bool("ft2m", false, "Feet to Meters")
	kg2lb := convCmd.Bool("kg2lb", false, "Kilograms to Pounds")
	lb2kg := convCmd.Bool("lb2kg", false, "Pounds to Kilograms")
	b2h := convCmd.Bool("b2h", false, "Bytes to Human readable")
	h2b := convCmd.Bool("h2b", false, "Human readable to Bytes")
	unit := convCmd.String("unit", "MB", "Unit for h2b conversion (B, KB, MB, GB, TB)")

	if len(os.Args) < 3 {
		ui.Header("UNIT CONVERTER")
		fmt.Println("Usage: go-cli-tool conv -val <number> [-c2f | -f2c | -m2ft | -ft2m | -kg2lb | -lb2kg | -b2h]")
		fmt.Println("Usage: go-cli-tool conv -val <number> -h2b -unit <unit>")
		os.Exit(1)
	}

	convCmd.Parse(os.Args[2:])

	if *val <= 0 {
		ui.Error("Value must be a positive number")
		return
	}

	switch {
	case *c2f:
		conv.CelsiusToFahrenheit(*val)
	case *f2c:
		conv.FahrenheitToCelsius(*val)
	case *m2ft:
		conv.MetersToFeet(*val)
	case *ft2m:
		conv.FeetToMeters(*val)
	case *kg2lb:
		conv.KgToLb(*val)
	case *lb2kg:
		conv.LbToKg(*val)
	case *b2h:
		conv.BytesToHuman(*val)
	case *h2b:
		conv.HumanToBytes(*val, *unit)
	default:
		ui.Error("Please specify a conversion flag (e.g., -c2f)")
		convCmd.Usage()
	}
}
595 lines•15.3 KB
go

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer