Skip to content

Commit

Permalink
add redditview
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Apr 11, 2023
1 parent 9898cc9 commit 78885b4
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 55 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GO_FILES = $(shell find . -type f -name '*.go')

.PHONY: all install clean test testrun

all: twitterview hackerview
all: twitterview hackerview redditview

hackerview: $(GO_FILES)
go build -race -v -ldflags="-s -w" ./cmd/$@
Expand All @@ -14,9 +14,14 @@ twitterview: $(GO_FILES)
go build -v -ldflags="-s -w" ./cmd/$@
ls -lh $@

install: hackerview twitterview
redditview: $(GO_FILES)
go build -v -ldflags="-s -w" ./cmd/$@
ls -lh $@

install: hackerview twitterview redditview
mv hackerview $(HOME)/go/bin/
mv twitterview $(HOME)/go/bin/
mv redditview $(HOME)/go/bin/

clean: ; go clean -x ./...
test: ; go test -vet=all -v ./...
Expand Down
59 changes: 59 additions & 0 deletions cmd/redditview/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main

import (
"errors"
"flag"
"fmt"
"io"
"log"
"os"
"time"

"github.com/azimut/cli-view/internal/reddit"
"github.com/fatih/color"
)

type options struct {
timeout time.Duration
useColors bool
userAgent string
width int
}

var opts options

func init() {
flag.DurationVar(&opts.timeout, "t", time.Second*5, "timeout in seconds")
flag.BoolVar(&opts.useColors, "C", true, "use colors")
flag.StringVar(&opts.userAgent, "A", "Reddit_Cli/0.1", "user agent to send to reddit")
flag.IntVar(&opts.width, "w", 80, "fixed with")
}

func usage() {
fmt.Printf("Usage: %s [OPTIONS] URL ...\n", os.Args[0])
flag.PrintDefaults()
}

func run(args []string, stdout io.Writer) error {
flag.Parse()
flag.Usage = usage
color.NoColor = !opts.useColors
if flag.NArg() != 1 {
flag.Usage()
return errors.New("missing URL argument")
}
url := flag.Args()[0]
thread, err := reddit.Fetch(url, opts.userAgent, opts.timeout)
if err != nil {
return err
}
fmt.Println(thread)
return nil
}

func main() {
err := run(os.Args, os.Stdout)
if err != nil {
log.Fatal(err)
}
}
52 changes: 36 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
module github.com/azimut/cli-view

go 1.17
go 1.20

require (
github.com/MichaelMure/go-term-markdown v0.1.4
github.com/MichaelMure/go-term-text v0.3.1
github.com/PuerkitoBio/goquery v1.7.1
github.com/charmbracelet/bubbles v0.9.0
github.com/charmbracelet/bubbletea v0.15.0
github.com/dustin/go-humanize v1.0.0
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
github.com/PuerkitoBio/goquery v1.8.1
github.com/caser/gophernews v0.0.0-20150107061403-f17255d5b792
github.com/charmbracelet/bubbles v0.15.0
github.com/charmbracelet/bubbletea v0.23.2
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.15.0
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
github.com/tidwall/gjson v1.14.4
)

require (
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/caser/gophernews v0.0.0-20150107061403-f17255d5b792
github.com/containerd/console v1.0.2 // indirect
github.com/alecthomas/chroma v0.7.1 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/aymanbagabas/go-osc52 v1.2.1 // indirect
github.com/charmbracelet/lipgloss v0.6.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dlclark/regexp2 v1.1.6 // indirect
github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect
github.com/kyokomi/emoji/v2 v2.2.8 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.9.0 // indirect
github.com/muesli/termenv v0.14.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167 // indirect
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/image v0.0.0-20191206065243-da761ea9ff43 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
)

replace github.com/jaytaylor/html2text => github.com/Necoro/html2text v0.0.0-20200510210923-a6c1c021f31e
Loading

0 comments on commit 78885b4

Please sign in to comment.