Skip to content

Commit

Permalink
schedule: fixed json schema creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkellerer committed Mar 10, 2024
1 parent 35f7b6a commit b850ecc
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
13 changes: 10 additions & 3 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,18 @@ func TestShowSchedules(t *testing.T) {
}
expected := strings.TrimSpace(`
schedule backup@default:
at: daily
at: daily
permission: auto
priority: background
lock-mode: default
capture-environment: RESTIC_*
schedule check@default:
at: weekly
at: weekly
permission: auto
priority: background
lock-mode: default
capture-environment: RESTIC_*
`)
showSchedules(buffer, schedules)
assert.Equal(t, expected, strings.TrimSpace(buffer.String()))
Expand Down
6 changes: 5 additions & 1 deletion config/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,11 @@ func customizeProperties(sectionName string, properties map[string]PropertyInfo)
}
if nested := property.PropertySet(); nested != nil {
if ps, ok := nested.(*namedPropertySet); ok {
customizeProperties("nested:"+nested.TypeName(), ps.properties)
name := fmt.Sprintf("nested:%s", nested.TypeName())
customizeProperties(name, ps.properties)
if ps.otherProperty != nil {
customizeProperties(name, map[string]PropertyInfo{"*": ps.otherProperty})
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/jsonschema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func schemaForGroups(version config.Version) SchemaType {
groups = newSchemaArray(newSchemaString())
describeAll(groups, "profile-name", "profile names in this group")
} else {
groups = schemaForPropertySet(config.NewGroupInfo())
groups = schemaForPropertySet(info)
}
groups.describe("group", "group declaration")
object.PatternProperties[matchAll] = groups
Expand Down
2 changes: 1 addition & 1 deletion config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ type ScheduleBaseSection struct {
ScheduleLockWait maybe.Duration `mapstructure:"schedule-lock-wait" show:"noshow" examples:"150s;15m;30m;45m;1h;2h30m" description:"Set the maximum time to wait for acquiring locks when running on schedule"`
ScheduleEnvCapture []string `mapstructure:"schedule-capture-environment" show:"noshow" default:"RESTIC_*" description:"Set names (or glob expressions) of environment variables to capture during schedule creation. The captured environment is applied prior to \"profile.env\" when running the schedule. Whether capturing is supported depends on the type of scheduler being used (supported in \"systemd\" and \"launchd\")"`
ScheduleIgnoreOnBattery maybe.Bool `mapstructure:"schedule-ignore-on-battery" show:"noshow" default:"false" description:"Don't start this schedule when running on battery"`
ScheduleIgnoreOnBatteryLessThan int `mapstructure:"schedule-ignore-on-battery-less-than" show:"noshow" default:"" examples:"20,33,50,75" description:"Don't start this schedule when running on battery and the state of charge is less than this percentage"`
ScheduleIgnoreOnBatteryLessThan int `mapstructure:"schedule-ignore-on-battery-less-than" show:"noshow" default:"" examples:"20;33;50;75" description:"Don't start this schedule when running on battery and the state of charge is less than this percentage"`
ScheduleAfterNetworkOnline maybe.Bool `mapstructure:"schedule-after-network-online" show:"noshow" description:"Don't start this schedule when the network is offline (supported in \"systemd\")"`
}

Expand Down
2 changes: 1 addition & 1 deletion config/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ScheduleBaseConfig struct {
LockWait maybe.Duration `mapstructure:"lock-wait" examples:"150s;15m;30m;45m;1h;2h30m" description:"Set the maximum time to wait for acquiring locks when running on schedule"`
EnvCapture []string `mapstructure:"capture-environment" default:"RESTIC_*" description:"Set names (or glob expressions) of environment variables to capture during schedule creation. The captured environment is applied prior to \"profile.env\" when running the schedule. Whether capturing is supported depends on the type of scheduler being used (supported in \"systemd\" and \"launchd\")"`
IgnoreOnBattery maybe.Bool `mapstructure:"ignore-on-battery" default:"false" description:"Don't start this schedule when running on battery"`
IgnoreOnBatteryLessThan int `mapstructure:"ignore-on-battery-less-than" default:"" examples:"20,33,50,75" description:"Don't start this schedule when running on battery and the state of charge is less than this percentage"`
IgnoreOnBatteryLessThan int `mapstructure:"ignore-on-battery-less-than" default:"" examples:"20;33;50;75" description:"Don't start this schedule when running on battery and the state of charge is less than this percentage"`
AfterNetworkOnline maybe.Bool `mapstructure:"after-network-online" description:"Don't start this schedule when the network is offline (supported in \"systemd\")"`
}

Expand Down
2 changes: 1 addition & 1 deletion flags.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"github.com/creativeprojects/clog"
"os"
"slices"
"strings"
"time"

"github.com/creativeprojects/clog"
"github.com/creativeprojects/resticprofile/constants"
"github.com/creativeprojects/resticprofile/platform"
"github.com/creativeprojects/resticprofile/term"
Expand Down
2 changes: 1 addition & 1 deletion flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"fmt"
"github.com/creativeprojects/clog"
"os"
"testing"
"time"

"github.com/creativeprojects/clog"
"github.com/creativeprojects/resticprofile/constants"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down

0 comments on commit b850ecc

Please sign in to comment.