Skip to content

Commit

Permalink
fix some bugs and add zsh auto completions support
Browse files Browse the repository at this point in the history
  • Loading branch information
nbebawy committed Jan 9, 2024
1 parent 58380b6 commit fc9d01a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ go.work
cleanup.sh
note.txt
preDeploy.sh
archub_amd64.tar.gz
*.tar.gz
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 nbebaw
Copyright (c) 2024 nbebaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ Archub is a command-line tool designed for managing packages in Arch Linux's AUR
## Dependencies
- <b>git</b>

## Installation
## Terminal Auto Completions support
- Zsh

## Installation without zsh auto completions
```sh
wget https://github.com/nbebaw/Archub/releases/download/v0.0.3/archub
chmod +x archub
sudo mv archub /usr/bin
```
## Installation with zsh auto completions
```sh
wget https://github.com/nbebaw/Archub/releases/download/v0.0.2/archub
mkdir archub_x86_64
cd archub_x86_64
wget https://github.com/nbebaw/Archub/releases/download/v0.0.3/archub_x86_64.tar.gz
tar -xvf archub_x86_64.tar.gz
chmod +x archub
sudo mv archub /usr/local/bin
sudo mv archub /usr/bin
sudo mv LICENSE /usr/share/licenses/archub
sudo mv auto_completions/zsh /usr/share/zsh/site-functions/_archub
```
## Usage

Expand All @@ -20,8 +34,8 @@ Usage:
archub [options]

Options:
-s, --search [options] : Search a package
-i, --install [options] : Install a package
-s, --search [package] : Search a package
-i, --install [package] : Install a package
-c, --clean : Clean up
-l, --list : List all aur installed Packages
-u, --update [package] : Update a Package
Expand Down
15 changes: 15 additions & 0 deletions auto_completions/zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#compdef archub

local options=(
{-s,--search}"[Search a package e.g. archub --search <package>]"
{-i,--install}"[Install a package e.g. archub --install <package]"
{-c,--clean}"[Clean up all tmp files and folders]"
{-l,--list}"[List all AUR installed Packages on your system]"
{-u,--update}'[Update a specific Package Sub Option: --all]:--all:(--all)'
{-d,--delete}'[Delete a specific Package e.g. archub --delete <package>]'
--check"[Check for package updates]"
--help"[How to use Archub]"
--version"[Version of Archub]"
)

_arguments $options
2 changes: 1 addition & 1 deletion lib/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getArchubDirSize() {
fmt.Println(err)
return
}
fmt.Printf("%s will be free\n", convertBytes(float64(totalSize), 1024.0))
fmt.Printf("%s is now a free space\n", convertBytes(float64(totalSize), 1024.0))
}

func MainCleanUp() {
Expand Down
4 changes: 2 additions & 2 deletions lib/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ func GetHelp() {
fmt.Println("Usage:")
fmt.Println(" archub [options]")
fmt.Println("\nOptions:")
fmt.Printf(" -s, --search [options] \t : Search a package\n")
fmt.Printf(" -i, --install [options] \t : Install a package\n")
fmt.Printf(" -s, --search [package] \t : Search a package\n")
fmt.Printf(" -i, --install [package] \t : Install a package\n")
fmt.Printf(" -c, --clean \t\t\t : Clean up\n")
fmt.Printf(" -l, --list \t\t\t : List all aur installed Packages\n")
fmt.Printf(" -u, --update [package] \t : Update a Package\n")
Expand Down
29 changes: 25 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func main() {
return
// -version || --version
case lib.ShowVersion:
if len(os.Args) > 2 {
fmt.Println("Error: Illegal option or argument.")
flag.Usage()
return
}
if flag.NArg() <= 0 {
fmt.Printf("archub v%s\n", Version)
return
Expand All @@ -33,15 +38,25 @@ func main() {
return
// -help || --help
case lib.Help:
if len(os.Args) > 2 {
fmt.Println("Error: Illegal option or argument.")
flag.Usage()
return
}
lib.MainHelp()
return

// -c || --c
// -c || --clean
case lib.CleanUp || lib.CleanUpAlias:
if len(os.Args) > 2 {
fmt.Println("Error: Illegal option or argument.")
flag.Usage()
return
}
lib.MainCleanUp()
return

// -s || --s
// -s || --search
case lib.SearchPkg || lib.SearchPkgAlias:
if flag.NArg() > 0 {
argumentPkg := flag.Arg(0)
Expand All @@ -52,7 +67,7 @@ func main() {
os.Exit(1)
}
return
// -i || --i
// -i || --install
case lib.InstallPkg || lib.InstallPkgAlias:
if flag.NArg() > 0 {
argumentPkg := flag.Arg(0)
Expand All @@ -65,6 +80,11 @@ func main() {
return
// -check || --check
case lib.CheckUpdatePkg:
if len(os.Args) > 2 {
fmt.Println("Options do not allowed together")
flag.Usage()
return
}
if flag.NArg() <= 0 {
updateExists := false
packageMap := lib.ListPackages()
Expand All @@ -75,7 +95,7 @@ func main() {
}
if packageVersion != newVersion {
fmt.Println("There is an update for the following packages:")
fmt.Printf("%s%s%s %s -> %s\n", lib.ColorRed, packageName, lib.ColorNone, packageVersion, newVersion)
fmt.Printf("%s%s%s %s -> %s\n", lib.ColorLightRed, packageName, lib.ColorNone, packageVersion, newVersion)
}
}
if !updateExists {
Expand All @@ -90,6 +110,7 @@ func main() {
return
// -u || --u [package]
case lib.UpdatePkg || lib.UpdatePkgAlias:
fmt.Println(flag.NArg())
if lib.UpdateAllPkg {
updateExists := false
// If both -u and --all flags are provided without an argument
Expand Down

0 comments on commit fc9d01a

Please sign in to comment.