mirror of
https://github.com/hanzoai/s3.git
synced 2026-10-30 14:59:09 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
175 lines
4.2 KiB
Go
175 lines
4.2 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/posener/complete"
|
|
completeinstall "github.com/posener/complete/cmd/install"
|
|
flag "github.com/seaweedfs/seaweedfs/weed/util/fla9"
|
|
)
|
|
|
|
func AutocompleteMain(commands []*Command) bool {
|
|
subCommands := make(map[string]complete.Command)
|
|
helpSubCommands := make(map[string]complete.Command)
|
|
for _, cmd := range commands {
|
|
flags := make(map[string]complete.Predictor)
|
|
cmd.Flag.VisitAll(func(flag *flag.Flag) {
|
|
flags["-"+flag.Name] = complete.PredictAnything
|
|
})
|
|
|
|
subCommands[cmd.Name()] = complete.Command{
|
|
Flags: flags,
|
|
}
|
|
helpSubCommands[cmd.Name()] = complete.Command{}
|
|
}
|
|
subCommands["help"] = complete.Command{Sub: helpSubCommands}
|
|
|
|
globalFlags := make(map[string]complete.Predictor)
|
|
flag.VisitAll(func(flag *flag.Flag) {
|
|
globalFlags["-"+flag.Name] = complete.PredictAnything
|
|
})
|
|
|
|
weedCmd := complete.Command{
|
|
Sub: subCommands,
|
|
Flags: globalFlags,
|
|
GlobalFlags: complete.Flags{"-h": complete.PredictNothing},
|
|
}
|
|
cmp := complete.New("s3", weedCmd)
|
|
|
|
return cmp.Complete()
|
|
}
|
|
|
|
func printAutocompleteScript(shell string) bool {
|
|
bin, err := os.Executable()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "failed to get executable path: %s\n", err)
|
|
return false
|
|
}
|
|
binPath, err := filepath.Abs(bin)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "failed to get absolute path: %s\n", err)
|
|
return false
|
|
}
|
|
|
|
switch shell {
|
|
case "bash":
|
|
fmt.Printf("complete -C %q s3\n", binPath)
|
|
case "zsh":
|
|
fmt.Printf("autoload -U +X bashcompinit && bashcompinit\n")
|
|
fmt.Printf("complete -o nospace -C %q s3\n", binPath)
|
|
case "fish":
|
|
fmt.Printf(`function __complete_s3
|
|
set -lx COMP_LINE (commandline -cp)
|
|
test -z (commandline -ct)
|
|
and set COMP_LINE "$COMP_LINE "
|
|
%q
|
|
end
|
|
complete -f -c s3 -a "(__complete_s3)"
|
|
`, binPath)
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "unsupported shell: %s. Supported shells: bash, zsh, fish\n", shell)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func installAutoCompletion() bool {
|
|
if runtime.GOOS == "windows" {
|
|
fmt.Println("Windows is not supported")
|
|
return false
|
|
}
|
|
|
|
err := completeinstall.Install("s3")
|
|
if err != nil {
|
|
fmt.Printf("install failed! %s\n", err)
|
|
return false
|
|
}
|
|
fmt.Printf("autocompletion is enabled. Please restart your shell.\n")
|
|
return true
|
|
}
|
|
|
|
func uninstallAutoCompletion() bool {
|
|
if runtime.GOOS == "windows" {
|
|
fmt.Println("Windows is not supported")
|
|
return false
|
|
}
|
|
|
|
err := completeinstall.Uninstall("s3")
|
|
if err != nil {
|
|
fmt.Printf("uninstall failed! %s\n", err)
|
|
return false
|
|
}
|
|
fmt.Printf("autocompletion is disabled. Please restart your shell.\n")
|
|
return true
|
|
}
|
|
|
|
var cmdAutocomplete = &Command{
|
|
Run: runAutocomplete,
|
|
UsageLine: "autocomplete [shell]",
|
|
Short: "generate or install shell autocomplete script",
|
|
Long: `Generate shell autocomplete script or install it to your shell configuration.
|
|
|
|
Usage:
|
|
s3 autocomplete [bash|zsh|fish] # print autocomplete script to stdout
|
|
s3 autocomplete install # install to shell config files
|
|
|
|
When a shell name is provided, the autocomplete script is printed to stdout.
|
|
You can then add it to your shell configuration manually, e.g.:
|
|
|
|
# For bash:
|
|
s3 autocomplete bash >> ~/.bashrc
|
|
|
|
# Or use eval in your shell config:
|
|
eval "$(s3 autocomplete bash)"
|
|
|
|
When 'install' is provided (or no argument), the script is automatically
|
|
installed to your shell configuration files.
|
|
|
|
Supported shells are bash, zsh, and fish.
|
|
Windows is not supported.
|
|
|
|
`,
|
|
}
|
|
|
|
func runAutocomplete(cmd *Command, args []string) bool {
|
|
if len(args) == 0 {
|
|
// Default behavior: install
|
|
return installAutoCompletion()
|
|
}
|
|
|
|
if len(args) > 1 {
|
|
cmd.Usage()
|
|
return false
|
|
}
|
|
|
|
shell := args[0]
|
|
if shell == "install" {
|
|
return installAutoCompletion()
|
|
}
|
|
|
|
// Print the autocomplete script for the specified shell
|
|
return printAutocompleteScript(shell)
|
|
}
|
|
|
|
var cmdUnautocomplete = &Command{
|
|
Run: runUnautocomplete,
|
|
UsageLine: "autocomplete.uninstall",
|
|
Short: "uninstall autocomplete",
|
|
Long: `s3 autocomplete is uninstalled in the shell.
|
|
|
|
Windows is not supported.
|
|
|
|
`,
|
|
}
|
|
|
|
func runUnautocomplete(cmd *Command, args []string) bool {
|
|
if len(args) != 0 {
|
|
cmd.Usage()
|
|
}
|
|
|
|
return uninstallAutoCompletion()
|
|
}
|