Skip to content

Commit

Permalink
fix incorrect extension for listings
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed May 5, 2023
1 parent 4cbeb3d commit abb8d95
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
7 changes: 4 additions & 3 deletions cmd/slackdump/internal/golang/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ func Render(s string) string {
// we're not running in the terminal, output the markdown source.
return s
}
if width == 0 {
if width < 40 {
width = defWidth
}
return md.RenderString(s, &md.TTYCodec{Width: width})

return md.RenderString(s, &md.TTYCodec{Width: width - 2})

// heavy-weight alternative:
// leftIndent := int(float64(width) * 0.075)
// rightIndent := int(float64(width) * 0.02)

// return string(markdown.Render(s, width-rightIndent, leftIndent))
}
2 changes: 1 addition & 1 deletion cmd/slackdump/internal/list/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func listChannels(ctx context.Context, cmd *base.Command, args []string) error {
ctx, task := trace.NewTask(ctx, "listChannels")
defer task.End()

var filename = makeFilename("channels", sess.Info().TeamID, listType)
var filename = makeFilename("channels", sess.Info().TeamID, ".json")
if len(args) > 0 {
filename = args[0]
}
Expand Down
15 changes: 2 additions & 13 deletions cmd/slackdump/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,10 @@ func fmtPrint(ctx context.Context, w io.Writer, a any, typ format.Type, u []slac
// unreachable
}

// extmap maps a format.Type to a file extension.
var extmap = map[format.Type]string{
format.CText: "txt",
format.CJSON: "json",
format.CCSV: "csv",
}

// makeFilename makes a filename for the given prefix, teamID and listType for
// channels and users.
func makeFilename(prefix string, teamID string, listType format.Type) string {
ext, ok := extmap[listType]
if !ok {
panic(fmt.Sprintf("unknown list type: %v", listType))
}
return fmt.Sprintf("%s-%s.%s", prefix, teamID, ext)
func makeFilename(prefix string, teamID string, ext string) string {
return fmt.Sprintf("%s-%s%s", prefix, teamID, ext)
}

func wizard(ctx context.Context, listFn listFunc) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/slackdump/internal/list/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Users are cached for %v. To disable caching, use '-no-user-cache' flag and

func listUsers(ctx context.Context, cmd *base.Command, args []string) error {
if err := list(ctx, func(ctx context.Context, sess *slackdump.Session) (any, string, error) {
var filename = makeFilename("users", sess.Info().TeamID, listType)
var filename = makeFilename("users", sess.Info().TeamID, ".json")
if len(args) > 0 {
filename = args[0]
}
Expand All @@ -44,7 +44,7 @@ func listUsers(ctx context.Context, cmd *base.Command, args []string) error {

func wizUsers(ctx context.Context, cmd *base.Command, args []string) error {
return wizard(ctx, func(ctx context.Context, sess *slackdump.Session) (any, string, error) {
var filename = makeFilename("users", sess.Info().TeamID, listType)
var filename = makeFilename("users", sess.Info().TeamID, ".json")
users, err := sess.GetUsers(ctx)
return users, filename, err
})
Expand Down

0 comments on commit abb8d95

Please sign in to comment.