feat: add --indent flag to control line indentation in remind output
- Introduces an 'indent' integer flag to the CLI for specifying the number of spaces to indent lines in the remind output. - Updates Task.ToRemind to accept an indent parameter and apply heading spaces accordingly. - Adjusts main.go to pass the indent value from the flag to ToRemind.
This commit is contained in:
@@ -26,7 +26,7 @@ type Task struct {
|
||||
Metadata map[string][]string `json:"metadata"`
|
||||
}
|
||||
|
||||
func (t Task) ToRemind() string {
|
||||
func (t Task) ToRemind(indent int) string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("REM TODO ")
|
||||
if t.DueDate == nil {
|
||||
@@ -87,6 +87,8 @@ func (t Task) ToRemind() string {
|
||||
sb.WriteString(" (%b)")
|
||||
}
|
||||
|
||||
headingSpaces := strings.Repeat(" ", indent)
|
||||
|
||||
if len(t.Metadata) > 0 {
|
||||
for k, values := range t.Metadata {
|
||||
if k == "due" {
|
||||
@@ -95,11 +97,11 @@ func (t Task) ToRemind() string {
|
||||
// uppercase first letter for Remind
|
||||
kUpper := strings.ToUpper(k[:1]) + k[1:]
|
||||
if len(values) == 1 {
|
||||
sb.WriteString(fmt.Sprintf("%%_%s: %%<%s>", kUpper, kUpper))
|
||||
sb.WriteString(fmt.Sprintf("%%_%s%s: %%<%s>", headingSpaces, kUpper, kUpper))
|
||||
} else {
|
||||
for i := range values {
|
||||
kNumbered := fmt.Sprintf("%s%d", kUpper, i+1)
|
||||
sb.WriteString(fmt.Sprintf("%%_%s: %%<%s>", kNumbered, kNumbered))
|
||||
sb.WriteString(fmt.Sprintf("%%_%s%s: %%<%s>", headingSpaces, kNumbered, kNumbered))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
main.go
4
main.go
@@ -14,6 +14,7 @@ var (
|
||||
inputFile string
|
||||
outputFile string
|
||||
debug bool
|
||||
indent int
|
||||
version = "v3.0.0"
|
||||
)
|
||||
|
||||
@@ -59,7 +60,7 @@ func main() {
|
||||
}
|
||||
|
||||
for _, t := range tasks {
|
||||
rem := t.ToRemind()
|
||||
rem := t.ToRemind(indent)
|
||||
if rem == "" {
|
||||
continue
|
||||
}
|
||||
@@ -71,6 +72,7 @@ func main() {
|
||||
rootCmd.Flags().StringVarP(&inputFile, "input", "i", "", "Input file (default: stdin)")
|
||||
rootCmd.Flags().StringVarP(&outputFile, "output", "o", "", "Output file (default: stdout)")
|
||||
rootCmd.Flags().BoolVar(&debug, "debug", false, "Print intermediate JSON to stderr")
|
||||
rootCmd.Flags().IntVar(&indent, "indent", 0, "Number of spaces to indent lines (from second line onward)")
|
||||
rootCmd.Version = version
|
||||
rootCmd.Flags().BoolP("version", "v", false, "Show version and exit")
|
||||
rootCmd.SetVersionTemplate(fmt.Sprintf("todotxt2remind version %s\n", version))
|
||||
|
||||
Reference in New Issue
Block a user