Skip to content

Commit

Permalink
Refactor the code so that fzf can be used as a library (#3769)
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn authored May 6, 2024
1 parent 065b9e6 commit e8405f4
Show file tree
Hide file tree
Showing 32 changed files with 1,150 additions and 891 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ all: target/$(BINARY)
test: $(SOURCES)
[ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)
SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \
github.com/junegunn/fzf \
github.com/junegunn/fzf/src \
github.com/junegunn/fzf/src/algo \
github.com/junegunn/fzf/src/tui \
Expand Down
35 changes: 31 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package main
import (
_ "embed"
"fmt"
"os"
"strings"

fzf "github.com/junegunn/fzf/src"
"github.com/junegunn/fzf/src/protector"
)

var version string = "0.51"
var revision string = "devel"
var version = "0.51"
var revision = "devel"

//go:embed shell/key-bindings.bash
var bashKeyBindings []byte
Expand All @@ -33,9 +34,21 @@ func printScript(label string, content []byte) {
fmt.Println("### end: " + label + " ###")
}

func exit(code int, err error) {
if err != nil {
os.Stderr.WriteString(err.Error() + "\n")
}
os.Exit(code)
}

func main() {
protector.Protect()
options := fzf.ParseOptions()

options, err := fzf.ParseOptions(true, os.Args[1:])
if err != nil {
exit(fzf.ExitError, err)
return
}
if options.Bash {
printScript("key-bindings.bash", bashKeyBindings)
printScript("completion.bash", bashCompletion)
Expand All @@ -51,5 +64,19 @@ func main() {
fmt.Println("fzf_key_bindings")
return
}
fzf.Run(options, version, revision)
if options.Help {
fmt.Print(fzf.Usage)
return
}
if options.Version {
if len(revision) > 0 {
fmt.Printf("%s (%s)\n", version, revision)
} else {
fmt.Println(version)
}
return
}

code, err := fzf.Run(options)
exit(code, err)
}
174 changes: 0 additions & 174 deletions main_test.go

This file was deleted.

Loading

0 comments on commit e8405f4

Please sign in to comment.