Skip to content

Commit

Permalink
feat: add explore command for fetching and managing feeds from reposi…
Browse files Browse the repository at this point in the history
…tories
  • Loading branch information
radulucut committed Jan 28, 2025
1 parent b2019a6 commit 0a4984d
Show file tree
Hide file tree
Showing 11 changed files with 958 additions and 24 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,41 @@ cleed config --color-range
cleed config --summary=1
```

#### Explore feeds

```bash
# Explore feeds from the default repository (https://github.com/radulucut/cleed-explore)
cleed explore

# Fetch the latest changes and explore feeds from the default repository
cleed explore --update

# Explore feeds from a repository
cleed explore https://github.com/radulucut/cleed-explore.git

# Limit the number of items to display from each list
cleed explore --limit 5

# Search for items (title, description)
cleed explore --search "news"

# Import all feeds into my feeds
cleed explore --import --limit 0

# Remove a repository
cleed explore https://github.com/radulucut/cleed-explore.git --remove
```

> **Note**
>
> The explore command expects git to be installed in order to fetch the repository, and it will only look at `.opml` files when exploring a repository.
#### Help

```bash
cleed --help
```

> **Color mapping**
>
> You can map the colors used in the feed reader to any color you want. This is useful if certain colors are not visible in your terminal based on the color scheme that you are using.
Expand Down
80 changes: 80 additions & 0 deletions cmd/cleed/explore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cleed

import (
"github.com/radulucut/cleed/internal"
"github.com/spf13/cobra"
)

func (r *Root) initExplore() {
cmd := &cobra.Command{
Use: "explore",
Short: "Explore feeds",
Long: `Explore feeds from a repository
Examples:
# Explore feeds from the default repository
cleed explore
# Fetch the latest changes and explore feeds from the default repository
cleed explore --update
# Explore feeds from a repository
cleed explore https://github.com/radulucut/cleed-explore.git
# Limit the number of items to display from each list
cleed explore --limit 5
# Search for items (title, description)
cleed explore --search "news"
# Import all feeds into my feeds
cleed explore --import --limit 0
# Remove a repository
cleed explore https://github.com/radulucut/cleed-explore.git --remove
`,

RunE: r.RunExplore,
}

flags := cmd.Flags()
flags.Bool("import", false, "import feeds")
flags.Uint("limit", 10, "limit the number of items to display from each list")
flags.String("search", "", "search for items (title, description)")
flags.BoolP("update", "u", false, "fetch the latest changes")
flags.Bool("remove", false, "remove the repository")

r.Cmd.AddCommand(cmd)
}

func (r *Root) RunExplore(cmd *cobra.Command, args []string) error {
if cmd.Flag("remove").Changed {
url := ""
if len(args) > 0 {
url = args[0]
}
return r.feed.ExploreRemove(url)
}
limit, err := cmd.Flags().GetUint("limit")
if err != nil {
return err
}
opts := &internal.ExploreOptions{
Limit: int(limit),
Update: cmd.Flag("update").Changed,
Query: cmd.Flag("search").Value.String(),
}
if len(args) > 0 {
opts.Url = args[0]
}
if opts.Query != "" {
if !cmd.Flag("limit").Changed {
opts.Limit = 25
}
return r.feed.ExploreSearch(opts)
}
if cmd.Flag("import").Changed {
return r.feed.ExploreImport(opts)
}
return r.feed.Explore(opts)
}
Loading

0 comments on commit 0a4984d

Please sign in to comment.