Skip to content

Commit

Permalink
Have our cache admin scripts be their own stem
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Feb 3, 2024
1 parent 224e86c commit aea5d31
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
paths:
- .github/workflows/deploy.yml
- .github/scripts/*
- scripts/*
pull_request:
paths:
- .github/workflows/deploy.yml
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ To use the script the user would type `mash foo bar` or alternatively
> letter category that you want an exception made, open a discussion and let’s
> chat!
> [!INFO]
> ### Naming Guidelines: A Call for Consideration
> Think for a little about the names you are picking. We reserve the right
> to rename egregious abuse of names and namespaces.
 


Expand Down
20 changes: 20 additions & 0 deletions scripts/cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env -S pkgx +mash bash

usage() {
echo "usage: mash pkgx/cache <ls|upgrade>"
}

cmd="$1"
shift

case "$cmd" in
neophile|neophilia|neophiliac)
exec pkgx mash "pkgx/cache+upgrade" "$@";;
ls|cache)
exec pkgx mash "pkgx/cache+$cmd" "$@";;
--help)
usage;;
*)
usage
exit 64;
esac
37 changes: 37 additions & 0 deletions scripts/cache+ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env -S pkgx +gum +gem bash

ruby "$0" | gum format
exit 0

#!/usr/bin/ruby
require 'pathname'

def find_versions(dir, result)
Dir.foreach(dir) do |entry|
next if entry == '.' || entry == '..' # Skip current and parent directories

path = File.join(dir, entry)

if File.directory?(path) && !File.symlink?(path)
if entry =~ /^v\d+\./
version = entry.sub(/^v/, '')
parent_dir = Pathname.new(dir).relative_path_from($pkgx_dir)
result << "| #{parent_dir} | #{version} |"
else
find_versions(path, result) # Recursively call for subdirectories
end
end
end
end

# Define the path to the .pkgx directory
$pkgx_dir = File.expand_path('~/.pkgx')
result = []

# Start the recursive search
find_versions($pkgx_dir, result)

# Output the Markdown table
puts "| Parent Directory | Version |"
puts "|------------------|---------|"
puts result.join("\n")
File renamed without changes.
38 changes: 2 additions & 36 deletions scripts/ls
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
#!/usr/bin/env -S pkgx +gum +gem bash
#!/usr/bin/env -S pkgx +mash bash

ruby "$0" | gum format
exit 0

#!/usr/bin/ruby
require 'pathname'

def find_versions(dir, result)
Dir.foreach(dir) do |entry|
next if entry == '.' || entry == '..' # Skip current and parent directories

path = File.join(dir, entry)

if File.directory?(path) && !File.symlink?(path)
if entry =~ /^v\d+\./
version = entry.sub(/^v/, '')
parent_dir = Pathname.new(dir).relative_path_from($pkgx_dir)
result << "| #{parent_dir} | #{version} |"
else
find_versions(path, result) # Recursively call for subdirectories
end
end
end
end

# Define the path to the .pkgx directory
$pkgx_dir = File.expand_path('~/.pkgx')
result = []

# Start the recursive search
find_versions($pkgx_dir, result)

# Output the Markdown table
puts "| Parent Directory | Version |"
puts "|------------------|---------|"
puts result.join("\n")
exec mash pkgx/cache+ls "$@"
3 changes: 3 additions & 0 deletions scripts/upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env -S pkgx +mash bash

exec mash pkgx/cache+upgrade "$@"

0 comments on commit aea5d31

Please sign in to comment.