Skip to content

Commit

Permalink
Add cobra support
Browse files Browse the repository at this point in the history
  • Loading branch information
gjhenrique committed Dec 4, 2022
1 parent f57e429 commit 59c3d31
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lfzf
44 changes: 44 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "lfzf",
Short: "Launcher using fzf and modes",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) { fmt.Println("hihi") },
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.lfzf.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"bytes"
"errors"
"fmt"

toml "github.com/pelletier/go-toml/v2"

"github.com/spf13/cobra"
"github.com/gjhenrique/lfzf/cmd"

"io"
"os"
Expand Down Expand Up @@ -48,7 +49,6 @@ func fzf(input []byte) (string, error) {
ownExe, err := os.Executable()
bind := fmt.Sprintf("change:reload:sleep 0.1; %s search {q} || true", ownExe)
cmd := exec.Command("fzf", "--ansi", "--sort", "--extended", "--no-multi", "--cycle", "--no-info", "--bind", bind)
fmt.Println(cmd.Args)
cmd.Stdout = &result
cmd.Stderr = os.Stderr

Expand Down Expand Up @@ -159,11 +159,12 @@ func findModes(configFile string) ([]*Mode, error) {
}

func main() {
if len(os.Args[1:]) > 0 {
fmt.Println("d\ne")
} else {
fzf([]byte("a\nb"))
}
// if len(os.Args[1:]) > 0 {
// fmt.Println("d\ne")
// } else {
// fzf([]byte("a\nb"))
// }
cmd.Execute()
// entries, err := GetDesktopEntries()

// if err != nil {
Expand Down

0 comments on commit 59c3d31

Please sign in to comment.