-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add self-update command and unify versioning to v9.1.0 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
33182b6
8398a43
1fed73f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 9.0.1 | ||
| 9.1.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "os/user" | ||
| "path/filepath" | ||
|
|
||
| "BanglaCode/src/Update" | ||
| "BanglaCode/src/evaluator" | ||
| "BanglaCode/src/evaluator/builtins" | ||
| "BanglaCode/src/lexer" | ||
|
|
@@ -27,7 +28,12 @@ func main() { | |
| return | ||
| } | ||
|
|
||
| // Check for flags | ||
| // Check for commands and flags | ||
| if len(os.Args) == 2 && update.CheckUpdateCommand(os.Args[1:], "update") { | ||
| update.Updater() | ||
| return | ||
| } | ||
|
|
||
| if os.Args[1] == "--help" || os.Args[1] == "-h" { | ||
| printHelp() | ||
| return | ||
|
|
@@ -55,6 +61,7 @@ func printHelp() { | |
| fmt.Println("\033[1;33m▸ Usage:\033[0m") | ||
| fmt.Println(" \033[1;32mbanglacode\033[0m Start interactive REPL") | ||
| fmt.Println(" \033[1;32mbanglacode <file>\033[0m Execute a BanglaCode file") | ||
| fmt.Println(" \033[1;32mbanglacode update\033[0m Update to the latest version") | ||
| fmt.Println(" \033[1;32mbanglacode --help, -h\033[0m Show this help message") | ||
| fmt.Println(" \033[1;32mbanglacode --version, -v\033[0m Show version information") | ||
| fmt.Println("") | ||
|
|
@@ -66,6 +73,7 @@ func printHelp() { | |
| fmt.Println(" \033[0;34m$\033[0m banglacode hello.bang \033[2m# Run hello.bang file\033[0m") | ||
| fmt.Println(" \033[0;34m$\033[0m banglacode app.bangla \033[2m# Run app.bangla file\033[0m") | ||
| fmt.Println(" \033[0;34m$\033[0m banglacode server.bong \033[2m# Run server.bong file\033[0m") | ||
| fmt.Println(" \033[0;34m$\033[0m banglacode update \033[2m# Update to latest version\033[0m") | ||
| fmt.Println("") | ||
| fmt.Println("\033[1;36m╚══════════════════════════════════════════════════════════════════╝\033[0m") | ||
| fmt.Println(" 📄 For more information, see \033[1;35mSYNTAX.md\033[0m") | ||
|
|
@@ -74,10 +82,10 @@ func printHelp() { | |
|
|
||
| func printVersion() { | ||
| fmt.Println("\033[1;36m╔════════════════════════════════════════════════════════╗") | ||
| fmt.Println("║ BanglaCode v9.0.1 ║") | ||
| fmt.Println("║ BanglaCode v9.1.0 ║") | ||
| fmt.Println("║ A Programming Language in Bengali (Banglish) ║") | ||
| fmt.Println("╠════════════════════════════════════════════════════════╣\033[0m") | ||
| fmt.Println("\033[1;36m║\033[0m 📦 \033[1mVersion:\033[0m \033[1;32m9.0.1\033[0m \033[1;36m║\033[0m") | ||
| fmt.Println("\033[1;36m║\033[0m 📦 \033[1mVersion:\033[0m \033[1;32m9.1.0\033[0m \033[1;36m║\033[0m") | ||
|
Comment on lines
+85
to
+88
|
||
| fmt.Println("\033[1;36m║\033[0m 👨💻 \033[1mAuthor:\033[0m \033[1;35mAnkan Saha\033[0m \033[1;36m║\033[0m") | ||
| fmt.Println("\033[1;36m║\033[0m 🌍 \033[1mFrom:\033[0m \033[1;37mWest Bengal, India\033[0m \033[1;36m║\033[0m") | ||
| fmt.Println("\033[1;36m║\033[0m 🔗 \033[1mGitHub:\033[0m \033[1;34mhttps://github.com/nexoral/BanglaCode\033[0m \033[1;36m║\033[0m") | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||
| package update | ||||||
|
||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "os" | ||||||
| "os/exec" | ||||||
| "runtime" | ||||||
| "strings" | ||||||
| ) | ||||||
|
|
||||||
| // Update commands for each operating system | ||||||
| var updateCommands = map[string]updateCommand{ | ||||||
| "linux": { | ||||||
| shell: "bash", | ||||||
| shellArg: "-c", | ||||||
| script: "curl -fsSL https://raw.githubusercontent.com/nexoral/BanglaCode/main/Scripts/install.sh | bash", | ||||||
| }, | ||||||
| "darwin": { | ||||||
| shell: "bash", | ||||||
| shellArg: "-c", | ||||||
| script: "curl -fsSL https://raw.githubusercontent.com/nexoral/BanglaCode/main/Scripts/install.sh | bash", | ||||||
| }, | ||||||
| "windows": { | ||||||
| shell: "powershell", | ||||||
| shellArg: "-Command", | ||||||
| script: "irm https://raw.githubusercontent.com/nexoral/BanglaCode/main/Scripts/install.ps1 | iex", | ||||||
| }, | ||||||
|
Comment on lines
+16
to
+27
|
||||||
| } | ||||||
|
|
||||||
| type updateCommand struct { | ||||||
| shell string | ||||||
| shellArg string | ||||||
| script string | ||||||
| } | ||||||
|
|
||||||
| // Update checks if the update command was passed and executes the appropriate update script | ||||||
| func Updater() { | ||||||
|
||||||
| fmt.Println("\033[1;36m╔════════════════════════════════════════════════════════╗") | ||||||
| fmt.Println("║ Updating BanglaCode... ║") | ||||||
| fmt.Println("╚════════════════════════════════════════════════════════╝\033[0m") | ||||||
| fmt.Println() | ||||||
|
|
||||||
| // Detect operating system | ||||||
| currentOS := runtime.GOOS | ||||||
| cmd, exists := updateCommands[currentOS] | ||||||
|
|
||||||
| if !exists { | ||||||
| fmt.Fprintf(os.Stderr, "\033[31mError: Unsupported operating system '%s'\033[0m\n", currentOS) | ||||||
| fmt.Fprintf(os.Stderr, "Supported systems: Linux, macOS (darwin), Windows\n") | ||||||
| os.Exit(1) | ||||||
| } | ||||||
|
|
||||||
| fmt.Printf("Detected OS: \033[1;32m%s\033[0m\n", currentOS) | ||||||
| fmt.Printf("Running update command...\n\n") | ||||||
|
|
||||||
| // Execute the appropriate update command | ||||||
| command := exec.Command(cmd.shell, cmd.shellArg, cmd.script) | ||||||
| command.Stdout = os.Stdout | ||||||
| command.Stderr = os.Stderr | ||||||
|
|
||||||
| if err := command.Run(); err != nil { | ||||||
| fmt.Fprintf(os.Stderr, "\n\033[31mError: Update failed: %v\033[0m\n", err) | ||||||
| os.Exit(1) | ||||||
| } | ||||||
|
|
||||||
| fmt.Println("\n\033[1;32m✓ Update completed successfully!\033[0m") | ||||||
| } | ||||||
|
Comment on lines
+37
to
+67
|
||||||
|
|
||||||
| // checkUpdateCommand checks if the "update" argument is present in the command-line args | ||||||
|
||||||
| // checkUpdateCommand checks if the "update" argument is present in the command-line args | |
| // CheckUpdateCommand checks if the "update" argument is present in the command-line args |
Copilot
AI
Feb 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CheckUpdateCommand function is exported (starts with capital letter) but only used within main.go. Based on Go conventions and examining similar system packages in this codebase (like src/evaluator/builtins/system/), internal helper functions should be unexported unless they need to be part of the public API. Consider making this function unexported by renaming it to "checkUpdateCommand".
Copilot
AI
Feb 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function accepts a generic "target" parameter but it's only ever called with the hardcoded value "update". This adds unnecessary complexity. Consider simplifying the function signature to not take a target parameter, or document why this flexibility is needed if there are plans to support other commands in the future.
Copilot
AI
Feb 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Update package lacks test coverage. Given that this codebase has comprehensive test coverage for other packages (as seen in the test directory), the update functionality should also have tests. Consider adding tests that: 1) Verify CheckUpdateCommand correctly identifies the update argument, 2) Mock the exec.Command to test different OS scenarios without actually executing shell commands, 3) Test error handling for unsupported operating systems. This is particularly important for security-sensitive code that executes external commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks both that len(os.Args) == 2 AND that CheckUpdateCommand returns true. The CheckUpdateCommand function already validates the argument value, making the length check partially redundant with how it's being called. More importantly, this means "banglacode -h update" or "banglacode update extra-arg" would not trigger the update command, which may be unexpected behavior. Consider either: 1) Simplifying to just check for the "update" command regardless of other arguments, or 2) Explicitly validating that "update" is the only argument and showing an error for extra arguments.