-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_types.go
50 lines (45 loc) · 1.53 KB
/
output_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Package outputTypes includes all valid output types that Icarus supports.
// outputtypes use the internal processed calendar structure and format it for the output.
package outputTypes
import (
"fmt"
"github.com/akamensky/argparse"
"github.com/emersion/go-ical"
"github.com/thoas/go-funk"
"io"
"strings"
)
// OutputOptions hold basic options for all output types
type OutputOptions struct {
Columns []string
}
// The BaseOutputType is the basic interface for all output types
type BaseOutputType interface {
// Initialize can add arguments to the argument parser.
Initialize(parser *argparse.Parser) error
// Generate generates the output based on the given calendar and writes it to writer
Generate(calendar *ical.Calendar, writer io.Writer, options OutputOptions) error
// GetHelp returns a help string about what the output produces
GetHelp() string
}
// GetOutputTypes returns a list of enabled output types
func GetOutputTypes() map[string]BaseOutputType {
m := make(map[string]BaseOutputType)
m["ics"] = &ICSOutputType{}
m["list"] = &ListOutputType{}
m["table"] = &TableOutputType{}
m["csv"] = &CSVOutputType{}
return m
}
// GetOutputHelp returns a formatted help string for all available output types
func GetOutputHelp() string {
outputTypes := GetOutputTypes()
return strings.Join(
funk.Reduce(
funk.Keys(outputTypes),
func(helps []string, outputType string) []string {
return append(helps, fmt.Sprintf("\t\t\t%s: %s", outputType, outputTypes[outputType].GetHelp()))
},
[]string{},
).([]string), "\n")
}