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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
// Package config loads lectio's INI configuration file.
//
// Resolution order: LECTIO_CONFIG env var -> ~/.config/lectio/config.ini
// (auto-seeded from the embedded default on first run, honoring
// XDG_CONFIG_HOME via os.UserConfigDir()) -> built-in defaults. A pre-existing
// config.toml (lectio's former format) at the default location is converted to
// config.ini once, on first run, and left on disk. INI that fails to parse
// falls back to defaults with a warning on stderr.
package config
import (
"fmt"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"github.com/pelletier/go-toml/v2"
"github.com/lukaszkasprzak/lectio/internal/bible"
"github.com/lukaszkasprzak/lectio/internal/calendar"
"github.com/lukaszkasprzak/lectio/internal/ini"
)
// configHeader is the reference comment block written at the top of every
// generated config.ini (the first-run seed and every Save), documenting each
// option's allowed values. Full-line comments only, so the INI reader skips
// them and values stay verbatim.
const configHeader = `# lectio configuration (INI). Full-line comments only (# or ;); no inline comments.
# Lists are comma-separated. Booleans are true/false.
#
# Allowed values:
# lectionary new | traditional (new = modern OF; traditional = 1962 EF)
# traditional_lang pl | en (vernacular for traditional propers)
# versions any of: bt, wuj, vul, grb, drb (comma list; bt = Biblia Tysiąclecia)
# default_version bt | wuj | vul | grb | drb
# width integer; 0 = detect terminal width
# all true | false (all readings, or just the gospel)
# offline true | false (never fetch; cache/sigla only)
# ui_language en | pl (interface chrome; readings stay source-language)
# reading_lang language for offline reading text (e.g. en, pl); blank follows ui_language
# reading_version force a specific bible corpus code (e.g. drb, wuj); blank = auto-resolve
# sigla_style auto | polish | english | latin (citation dialect; auto follows ui_language)
# web_theme a theme name (see docs/THEMES.md)
# web_port integer; 0 = try 1099, then any free port
# web_display horizontal | vertical | interlinear
# web_mono true | false (monospace reading face in the web UI)
# web_versions any of: bt, wuj, vul, grb, drb (comma list); empty = just default_version
# pager shell command, e.g. less -R; empty = off
# use calendar layers to stack over the universal calendar: names of
# ~/.config/lectio/calendars/<name>.ini files (comma list, order = precedence)
#
# [calendar] — computed-calendar placement options (defaults = Universal Roman Calendar):
# epiphany fixed | sunday (fixed = Jan 6; sunday = the Sunday of Jan 2-8)
# ascension thursday | sunday (sunday = moved to the following Sunday, 7th of Easter)
# corpus_christi thursday | sunday (sunday = moved to the following Sunday)
#
# Optional [parts.new] / [parts.traditional] sections hide reading parts, e.g.:
# [parts.new]
# psalm = false
`
// Version is lectio's release version, shared by every binary's
// -v/--version output (lectio, lectio-ui, lectio-web).
const Version = "0.34.0"
// validVersions are the five scripture versions lectio understands.
var validVersions = map[string]bool{
"bt": true,
"wuj": true,
"vul": true,
"grb": true,
"drb": true,
}
// ValidVersion reports whether v is one of the five scripture versions
// lectio understands (bt, wuj, vul, grb, drb).
func ValidVersion(v string) bool {
return validVersions[v]
}
// NormalizeLectionary maps -l/--lectionary's accepted spellings ("new",
// "trad", "traditional") onto the canonical Config.Lectionary values ("new",
// "traditional"); anything else reports ok=false.
func NormalizeLectionary(s string) (string, bool) {
switch strings.ToLower(s) {
case "new":
return "new", true
case "trad", "traditional":
return "traditional", true
default:
return "", false
}
}
// validDisplays are the lectio-web reading-pane layouts.
var validDisplays = map[string]bool{
"horizontal": true,
"vertical": true,
"interlinear": true,
}
// NormalizeDisplay lower-cases display and falls back to "horizontal" when
// it is not one of validDisplays -- the same lenient style as the rest of
// lectio-web's config fields (no error, just a safe default). Exported so
// internal/web can apply the identical normalization to an explicit
// ?display= query override, keeping the valid set in this one place.
func NormalizeDisplay(display string) string {
d := strings.ToLower(display)
if !validDisplays[d] {
return "horizontal"
}
return d
}
// validUILanguages are the two UI chrome languages lectio understands.
var validUILanguages = map[string]bool{
"en": true,
"pl": true,
}
// NormalizeUILanguage lower-cases lang and falls back to "en" when it is not
// one of validUILanguages -- the same lenient style as NormalizeDisplay (no
// error, just a safe default).
func NormalizeUILanguage(lang string) string {
l := strings.ToLower(lang)
if !validUILanguages[l] {
return "en"
}
return l
}
// NormalizeSiglaStyle maps a sigla_style setting to one of "auto", "polish",
// "english"; anything unrecognised (incl. "") falls back to "auto". Accepts the
// short aliases "pl"/"en" for convenience.
func NormalizeSiglaStyle(s string) string {
switch strings.ToLower(strings.TrimSpace(s)) {
case "polish", "pl":
return "polish"
case "latin", "la":
return "latin"
case "english", "en":
return "english"
default:
return "auto"
}
}
// Config holds lectio's user-configurable settings. The toml tags are used only
// by the one-shot config.toml -> config.ini migration; the live format is INI.
type Config struct {
SchemaVersion int `toml:"schema_version"`
Lectionary string `toml:"lectionary"`
TraditionalLang string `toml:"traditional_lang"`
Versions []string `toml:"versions"`
DefaultVersion string `toml:"default_version"`
Width int `toml:"width"`
All bool `toml:"all"`
Offline bool `toml:"offline"`
UILanguage string `toml:"ui_language"`
ReadingLang string `toml:"reading_lang"`
ReadingVersion string `toml:"reading_version"`
SiglaStyle string `toml:"sigla_style"`
WebTheme string `toml:"web_theme"`
WebPort int `toml:"web_port"`
WebDisplay string `toml:"web_display"`
WebMono bool `toml:"web_mono"`
WebVersions []string `toml:"web_versions"`
Pager string `toml:"pager"`
Parts map[string]map[string]bool `toml:"parts"`
// Computed-calendar placement options (INI [calendar] section; INI-only).
CalEpiphany string `toml:"-"`
CalAscension string `toml:"-"`
CalCorpusChristi string `toml:"-"`
// Use is the ordered stack of user calendar-layer ids (INI "use"); each id
// names a <CalendarsDir>/<id>.ini file layered over the universal calendar.
Use []string `toml:"-"`
}
// PartShown reports whether a part renders: true unless explicitly set false.
func (c Config) PartShown(lectionary, partID string) bool {
if m, ok := c.Parts[lectionary]; ok {
if v, ok := m[partID]; ok {
return v
}
}
return true
}
// SiglaLang resolves the book dialect (a books.toml section code, "en"/"pl")
// that `lectio --ref`/`--list` use: the explicit sigla_style, or -- when "auto"
// -- the UI language.
func (c Config) SiglaLang() string {
switch c.SiglaStyle {
case "polish":
return "pl"
case "latin":
return "la"
case "english":
return "en"
default:
if c.UILanguage == "pl" {
return "pl"
}
return "en"
}
}
// ReadingCorpus resolves which bible corpus renders offline reading text:
// an explicit reading_version, else the first corpus matching reading_lang,
// else the first matching ui_language, else "" (caller uses the Latin vul).
func (c Config) ReadingCorpus() string {
if c.ReadingVersion != "" {
if _, ok := bible.Meta(c.ReadingVersion); ok {
return c.ReadingVersion
}
}
for _, lang := range []string{c.ReadingLang, NormalizeUILanguage(c.UILanguage)} {
if lang == "" {
continue
}
for _, m := range bible.CorporaForLang(lang) {
if m.Autoselect { // skip explicit-only corpora (e.g. the incomplete wuj)
return m.Code
}
}
}
return ""
}
// Selection maps the config onto the calendar engine's Selection: the form
// (from Lectionary: "new" -> OF, "traditional" -> EF) plus the national
// placement options, each falling back to the Universal Roman default.
func (c Config) Selection() calendar.Selection {
sel := calendar.DefaultSelection()
if c.Lectionary == "traditional" {
sel.Form = "old"
} else {
sel.Form = "new"
}
if c.CalEpiphany != "" {
sel.Epiphany = c.CalEpiphany
}
if c.CalAscension != "" {
sel.Ascension = c.CalAscension
}
if c.CalCorpusChristi != "" {
sel.CorpusChristi = c.CalCorpusChristi
}
return sel
}
// Default returns lectio's built-in configuration, used when no config file
// is found and as the base that a partial config file overrides.
func Default() Config {
return Config{
SchemaVersion: 1,
Lectionary: "new",
TraditionalLang: "pl",
Versions: []string{"bt", "wuj", "vul", "grb", "drb"},
DefaultVersion: "bt",
Width: 0,
All: false,
Offline: false,
UILanguage: "en",
SiglaStyle: "auto",
WebTheme: "transfiguration",
WebPort: 0,
WebDisplay: "horizontal",
WebMono: false,
WebVersions: nil,
Pager: "",
Parts: nil,
}
}
// configPath resolves the config file location: LECTIO_CONFIG if set,
// otherwise the default XDG-aware path under os.UserConfigDir(). The bool
// reports whether this is the default (seedable/migratable) location.
func configPath() (path string, isDefault bool, err error) {
if p := os.Getenv("LECTIO_CONFIG"); p != "" {
return p, false, nil
}
dir, err := os.UserConfigDir()
if err != nil {
return "", false, err
}
return filepath.Join(dir, "lectio", "config.ini"), true, nil
}
// CalendarsDir returns the directory holding user calendar-layer files
// (<config dir>/calendars).
func CalendarsDir() (string, error) {
p, _, err := configPath()
if err != nil {
return "", err
}
return filepath.Join(filepath.Dir(p), "calendars"), nil
}
// CorporaDir is the user directory for drop-in bible corpora (<code>.tsv +
// <code>.ini), alongside calendars/ under the lectio config dir. Mirrors
// CalendarsDir exactly (verified: it uses configPath() then filepath.Dir).
func CorporaDir() (string, error) {
p, _, err := configPath()
if err != nil {
return "", err
}
return filepath.Join(filepath.Dir(p), "corpora"), nil
}
// BooksPath returns the path to the optional user books.ini (in the same
// directory as the config file). There is no embedded seed on disk -- absence
// means "use the built-in defaults".
func BooksPath() (string, error) {
p, _, err := configPath()
if err != nil {
return "", err
}
return filepath.Join(filepath.Dir(p), "books.ini"), nil
}
// UserBooksINI returns the bytes of the optional user books.ini (see BooksPath),
// or nil when absent/unreadable -- callers then fall back to bible's embedded
// default table. A former books.toml at the same location is converted to
// books.ini once, on first read (the old file is kept).
func UserBooksINI() []byte {
p, err := BooksPath()
if err != nil {
return nil
}
if b, err := os.ReadFile(p); err == nil {
return b
}
tomlPath := filepath.Join(filepath.Dir(p), "books.toml")
data, err := os.ReadFile(tomlPath)
if err != nil {
return nil
}
out := booksTOMLtoINI(data)
if out == nil {
return nil
}
_ = os.WriteFile(p, out, 0o644)
fmt.Fprintf(os.Stderr, "lectio: migrated %s -> books.ini (old file kept)\n", tomlPath)
return out
}
// booksTOMLtoINI converts a former books.toml (dialect -> book -> [forms]) into
// books.ini. Returns nil if the TOML is unparseable.
func booksTOMLtoINI(data []byte) []byte {
var raw map[string]map[string][]string
if err := toml.Unmarshal(data, &raw); err != nil {
return nil
}
var b strings.Builder
b.WriteString("# lectio book names & abbreviations, per dialect (migrated from books.toml).\n")
emit := func(d string) {
books := raw[d]
if books == nil {
return
}
fmt.Fprintf(&b, "\n[%s]\n", d)
keys := make([]string, 0, len(books))
for k := range books {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Fprintf(&b, "%s = %s\n", k, strings.Join(books[k], ", "))
}
}
seen := map[string]bool{"en": true, "pl": true, "la": true}
emit("en")
emit("pl")
emit("la")
others := make([]string, 0)
for d := range raw {
if !seen[d] {
others = append(others, d)
}
}
sort.Strings(others)
for _, d := range others {
emit(d)
}
return []byte(b.String())
}
// seedIfMissing writes the embedded default config to path if nothing is
// there yet.
func seedIfMissing(path string) error {
if _, err := os.Stat(path); err == nil {
return nil
} else if !os.IsNotExist(err) {
return err
}
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
return os.WriteFile(path, renderConfigINI(Default()), 0o644)
}
// migrateFromTOML converts a former config.toml sitting next to iniPath into
// config.ini, once. The old file is left in place (so the change is
// reversible). A missing or unreadable config.toml is not an error.
func migrateFromTOML(iniPath string) {
tomlPath := filepath.Join(filepath.Dir(iniPath), "config.toml")
data, err := os.ReadFile(tomlPath)
if err != nil {
return
}
cfg := Default()
if err := toml.Unmarshal(data, &cfg); err != nil {
return
}
normalize(&cfg)
_ = Save(cfg) // writes config.ini
fmt.Fprintf(os.Stderr, "lectio: migrated %s -> config.ini (old file kept)\n", tomlPath)
}
// Load reads lectio's configuration, following the package's resolution order
// (see the package doc comment). It always returns a usable Config: on a
// missing config dir or an INI parse error it falls back to Default() (warning
// on stderr in the parse-error case). It returns a non-nil error only when the
// loaded config contains a semantically invalid value.
func Load() (Config, error) {
def := Default()
path, isDefault, err := configPath()
if err != nil {
fmt.Fprintf(os.Stderr, "lectio: warning: could not resolve config directory: %v; using defaults\n", err)
return def, nil
}
if isDefault {
if _, statErr := os.Stat(path); os.IsNotExist(statErr) {
migrateFromTOML(path) // convert a former config.toml if present
if err := seedIfMissing(path); err != nil {
return def, err
}
}
}
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
return def, nil
}
return def, err
}
cfg, err := readINI(data)
if err != nil {
fmt.Fprintf(os.Stderr, "lectio: warning: invalid config at %s: %v; using defaults\n", path, err)
return def, nil
}
normalize(&cfg)
if err := validate(cfg); err != nil {
return Config{}, err
}
return cfg, nil
}
// normalize applies the lenient field fix-ups Load enforces after parsing.
func normalize(cfg *Config) {
cfg.WebDisplay = NormalizeDisplay(cfg.WebDisplay)
cfg.UILanguage = NormalizeUILanguage(cfg.UILanguage)
cfg.SiglaStyle = NormalizeSiglaStyle(cfg.SiglaStyle)
}
// readINI parses INI bytes into a Config over Default(). Absent keys keep the
// default; present keys override (an empty list value clears the list).
func readINI(data []byte) (Config, error) {
cfg := Default()
secs, err := ini.Parse(data)
if err != nil {
return cfg, err
}
for _, s := range secs {
switch {
case s.Name == "":
for _, p := range s.Pairs {
applyScalar(&cfg, p.Key, p.Val)
}
case s.Name == "calendar":
for _, p := range s.Pairs {
switch p.Key {
case "epiphany":
cfg.CalEpiphany = p.Val
case "ascension":
cfg.CalAscension = p.Val
case "corpus_christi":
cfg.CalCorpusChristi = p.Val
}
}
case strings.HasPrefix(s.Name, "parts."):
lect := strings.TrimPrefix(s.Name, "parts.")
if cfg.Parts == nil {
cfg.Parts = map[string]map[string]bool{}
}
if cfg.Parts[lect] == nil {
cfg.Parts[lect] = map[string]bool{}
}
for _, p := range s.Pairs {
cfg.Parts[lect][p.Key] = p.Val == "true"
}
}
}
return cfg, nil
}
func applyScalar(cfg *Config, key, val string) {
switch key {
case "schema_version":
cfg.SchemaVersion = atoiOr(val, cfg.SchemaVersion)
case "lectionary":
cfg.Lectionary = val
case "traditional_lang":
cfg.TraditionalLang = val
case "versions":
cfg.Versions = ini.List(val)
case "default_version":
cfg.DefaultVersion = val
case "width":
cfg.Width = atoiOr(val, cfg.Width)
case "all":
cfg.All = val == "true"
case "offline":
cfg.Offline = val == "true"
case "ui_language":
cfg.UILanguage = val
case "reading_lang":
cfg.ReadingLang = val
case "reading_version":
cfg.ReadingVersion = val
case "sigla_style":
cfg.SiglaStyle = val
case "web_theme":
cfg.WebTheme = val
case "web_port":
cfg.WebPort = atoiOr(val, cfg.WebPort)
case "web_display":
cfg.WebDisplay = val
case "web_mono":
cfg.WebMono = val == "true"
case "web_versions":
cfg.WebVersions = ini.List(val)
case "pager":
cfg.Pager = val
case "use":
cfg.Use = ini.List(val)
}
}
func atoiOr(s string, def int) int {
if n, err := strconv.Atoi(strings.TrimSpace(s)); err == nil {
return n
}
return def
}
// validate checks the semantic constraints Load enforces beyond parsing.
func validate(cfg Config) error {
if cfg.Lectionary != "new" && cfg.Lectionary != "traditional" {
return fmt.Errorf("config: invalid lectionary %q (must be \"new\" or \"traditional\")", cfg.Lectionary)
}
if cfg.TraditionalLang != "pl" && cfg.TraditionalLang != "en" {
return fmt.Errorf("config: invalid traditional_lang %q (must be \"pl\" or \"en\")", cfg.TraditionalLang)
}
for _, v := range cfg.Versions {
if !validVersions[v] {
return fmt.Errorf("config: invalid version %q in versions (must be one of bt, wuj, vul, grb, drb)", v)
}
}
if !validVersions[cfg.DefaultVersion] {
return fmt.Errorf("config: invalid default_version %q (must be one of bt, wuj, vul, grb, drb)", cfg.DefaultVersion)
}
for _, v := range cfg.WebVersions {
if !validVersions[v] {
return fmt.Errorf("config: invalid version %q in web_versions (must be one of bt, wuj, vul, grb, drb)", v)
}
}
return nil
}
// Validate exposes the semantic checks Load applies, so callers that build a
// Config (the web /settings form) can reject an invalid one before saving.
func Validate(cfg Config) error { return validate(cfg) }
// Save writes cfg to the config file (configPath, honoring LECTIO_CONFIG),
// creating the directory if needed, as commented INI.
func Save(cfg Config) error {
path, _, err := configPath()
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
return os.WriteFile(path, renderConfigINI(cfg), 0o644)
}
// renderConfigINI regenerates config.ini from cfg. Comments are on their own
// lines so no value ever shares a line with a "#"/";" comment character.
func renderConfigINI(cfg Config) []byte {
var b strings.Builder
b.WriteString(configHeader)
b.WriteString("\n")
fmt.Fprintf(&b, "schema_version = %d\n", cfg.SchemaVersion)
fmt.Fprintf(&b, "lectionary = %s\n", cfg.Lectionary)
fmt.Fprintf(&b, "traditional_lang = %s\n", cfg.TraditionalLang)
fmt.Fprintf(&b, "versions = %s\n", strings.Join(cfg.Versions, ", "))
fmt.Fprintf(&b, "default_version = %s\n", cfg.DefaultVersion)
fmt.Fprintf(&b, "width = %d\n", cfg.Width)
fmt.Fprintf(&b, "all = %t\n", cfg.All)
fmt.Fprintf(&b, "offline = %t\n", cfg.Offline)
fmt.Fprintf(&b, "ui_language = %s\n", cfg.UILanguage)
fmt.Fprintf(&b, "reading_lang = %s\n", cfg.ReadingLang)
fmt.Fprintf(&b, "reading_version = %s\n", cfg.ReadingVersion)
fmt.Fprintf(&b, "sigla_style = %s\n", cfg.SiglaStyle)
fmt.Fprintf(&b, "web_theme = %s\n", cfg.WebTheme)
fmt.Fprintf(&b, "web_port = %d\n", cfg.WebPort)
fmt.Fprintf(&b, "web_display = %s\n", cfg.WebDisplay)
fmt.Fprintf(&b, "web_mono = %t\n", cfg.WebMono)
fmt.Fprintf(&b, "web_versions = %s\n", strings.Join(cfg.WebVersions, ", "))
fmt.Fprintf(&b, "pager = %s\n", cfg.Pager)
fmt.Fprintf(&b, "use = %s\n", strings.Join(cfg.Use, ", "))
b.WriteString("\n# Computed-calendar national placement options.\n[calendar]\n")
fmt.Fprintf(&b, "epiphany = %s\n", orDefault(cfg.CalEpiphany, "fixed"))
fmt.Fprintf(&b, "ascension = %s\n", orDefault(cfg.CalAscension, "thursday"))
fmt.Fprintf(&b, "corpus_christi = %s\n", orDefault(cfg.CalCorpusChristi, "thursday"))
// Preserve the parts map (per-lectionary hide flags) across a Save.
lects := make([]string, 0, len(cfg.Parts))
for l := range cfg.Parts {
lects = append(lects, l)
}
sort.Strings(lects)
for _, l := range lects {
parts := cfg.Parts[l]
keys := make([]string, 0, len(parts))
for k := range parts {
keys = append(keys, k)
}
sort.Strings(keys)
fmt.Fprintf(&b, "\n[parts.%s]\n", l)
for _, k := range keys {
fmt.Fprintf(&b, "%s = %t\n", k, parts[k])
}
}
return []byte(b.String())
}
func orDefault(v, def string) string {
if v == "" {
return def
}
return v
}
|