Skip to content

Commit

Permalink
(feat)!: global update, interface change and project structure change
Browse files Browse the repository at this point in the history
  • Loading branch information
neptship committed Jul 2, 2024
1 parent 670d4d4 commit 98bfa1d
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 355 deletions.
36 changes: 0 additions & 36 deletions .golangci.yml

This file was deleted.

21 changes: 0 additions & 21 deletions CONTRIBUTING.md

This file was deleted.

19 changes: 0 additions & 19 deletions Makefile

This file was deleted.

48 changes: 0 additions & 48 deletions cmd/add.go

This file was deleted.

35 changes: 0 additions & 35 deletions cmd/create.go

This file was deleted.

24 changes: 0 additions & 24 deletions cmd/list.go

This file was deleted.

103 changes: 74 additions & 29 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,98 @@
package cmd

import (
"fmt"
"os"
"strings"

"github.com/charmbracelet/log"
cc "github.com/ivanpirog/coloredcobra"
"github.com/manifoldco/promptui"
"github.com/neptship/ignore/internal"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "ignore",
Short: "Create files .ignore quickly and simply",
// Run: func(cmd *cobra.Command, args []string) { },
Run: func(cmd *cobra.Command, args []string) {
ignoreFile, err := chooseIgnoreFile()
if err != nil {
internal.CallClear()
os.Exit(1)
}
ignoreTemplate, err := chooseIgnoreTemplate()
if err != nil {
internal.CallClear()
os.Exit(1)
}
internal.AddIgnoreTemplate(ignoreFile, ignoreTemplate)
},
}

func chooseIgnoreFile() (string, error) {
tr := internal.NewTemplateRegistry()
templatesIgnore := tr.List()

templates := &promptui.SelectTemplates{
Active: `{{">" | blue | bold }} {{ . | blue | bold }}`,
Inactive: `{{.}}`,
Selected: `{{ "√ " | green | bold }} {{ "Choose .ignore file" | bold }} {{"»" | black}} {{ . | blue }}`,
Label: `{{ . | bold }}`,
}

prompt := promptui.Select{
Label: promptui.IconInitial + " Choose .ignore file",
Templates: templates,
Items: internal.IgnoreFiles,
Size: 8,
Searcher: func(input string, index int) bool {
pepper := templatesIgnore[index]
name := strings.Replace(strings.ToLower(pepper), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)

return strings.Contains(name, input)
},
}

_, ignoreFile, err := prompt.Run()
return ignoreFile, err
}

func chooseIgnoreTemplate() (string, error) {
tr := internal.NewTemplateRegistry()
templatesIgnore := tr.List()

templates := &promptui.SelectTemplates{
Active: `{{">" | blue | bold }} {{ . | blue | bold }}`,
Inactive: `{{ . | underline}}`,
Selected: `{{ "√ " | green | bold }} {{ "Choose .ignore template" | bold }} {{"»" | black}} {{ . | blue }}`,
Label: `{{ . | bold }}`,
}

prompt := promptui.Select{
Label: promptui.IconInitial + " Choose .ignore template",
Templates: templates,
Items: templatesIgnore,
Size: 8,
Searcher: func(input string, index int) bool {
pepper := templatesIgnore[index]
name := strings.Replace(strings.ToLower(pepper), " ", "", -1)
input = strings.Replace(strings.ToLower(input), " ", "", -1)

return strings.Contains(name, input)
},
}

_, ignoreTemplate, err := prompt.Run()
return ignoreTemplate, err
}

func Execute() {
cc.Init(&cc.Config{
RootCmd: rootCmd,
Headings: cc.HiBlue + cc.Bold + cc.Underline,
Commands: cc.HiYellow + cc.Bold,
Example: cc.Italic,
ExecName: cc.Bold,
Flags: cc.Bold,
FlagsDataType: cc.Italic + cc.HiBlue,
NoExtraNewlines: true,
NoBottomNewline: true,
})
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
internal.CallClear()
}
}

func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

func handleErr(err error) {
if err == nil {
return
}

log.Error(err)
_, _ = fmt.Fprintf(
os.Stderr,
"%s\n",
strings.Trim(err.Error(), " \n"),
)
os.Exit(1)
}
53 changes: 0 additions & 53 deletions cmd/version.go

This file was deleted.

Loading

0 comments on commit 98bfa1d

Please sign in to comment.