Added some comments

This commit is contained in:
Leons Aleksandrovs
2025-08-10 21:50:56 +03:00
parent 04a5a27cfe
commit 0d3fe297af

View File

@@ -11,11 +11,13 @@ import (
)
func main() {
// Check for arguments
if len(os.Args) < 2 {
fmt.Println("Usage: runner <file-or-directory>")
os.Exit(1)
}
// Select first argument, and check if it's a file or directory
targetPath := os.Args[1]
info, err := os.Stat(targetPath)
@@ -53,12 +55,14 @@ func main() {
}
func runCommandsFromFile(filename string, currentDir *string) error {
// Try to open the file
f, err := os.Open(filename)
if err != nil {
return fmt.Errorf("Error opening file: %w", err)
}
defer f.Close()
// Create a scanner to read the file line by line
scanner := bufio.NewScanner(f)
for scanner.Scan() {
cmdLine := strings.TrimSpace(scanner.Text())
@@ -86,6 +90,7 @@ func runCommandsFromFile(filename string, currentDir *string) error {
continue
}
// Execute the command
fmt.Println(">>> Executing:", cmdLine)
cmd := exec.Command("bash", "-c", cmdLine)
cmd.Stdout = os.Stdout