Skip to content

Commit d0ba684

Browse files
acarl005oz-agent
andcommitted
Add completion spec for timedatectl
Add JSON spec with subcommands (status, show, set-time, set-timezone, list-timezones, set-local-rtc, set-ntp, timesync-status, show-timesync) and global options. Includes a timezone_generator for dynamic timezone completions via timedatectl list-timezones. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent c059425 commit d0ba684

4 files changed

Lines changed: 156 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ signatures/new/command-signatures-*/src/commands
1515

1616
.idea/
1717
**/*.DS_Store
18+
node_modules/
1819

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"name": "timedatectl",
3+
"description": "Control the system time and date",
4+
"subcommands": [
5+
{
6+
"name": "status",
7+
"description": "Show current time settings"
8+
},
9+
{
10+
"name": "show",
11+
"description": "Show properties of systemd-timedated"
12+
},
13+
{
14+
"name": "set-time",
15+
"description": "Set system time",
16+
"args": {
17+
"name": "TIME",
18+
"description": "Time to set (format: \"YYYY-MM-DD HH:MM:SS\")"
19+
}
20+
},
21+
{
22+
"name": "set-timezone",
23+
"description": "Set system time zone",
24+
"args": {
25+
"name": "TIMEZONE",
26+
"generatorName": "timezone_generator"
27+
}
28+
},
29+
{
30+
"name": "list-timezones",
31+
"description": "Show known time zones"
32+
},
33+
{
34+
"name": "set-local-rtc",
35+
"description": "Control whether RTC is in local time",
36+
"args": {
37+
"name": "BOOL",
38+
"suggestions": [
39+
"true",
40+
"false"
41+
]
42+
}
43+
},
44+
{
45+
"name": "set-ntp",
46+
"description": "Control network time sync",
47+
"args": {
48+
"name": "BOOL",
49+
"suggestions": [
50+
"true",
51+
"false"
52+
]
53+
}
54+
},
55+
{
56+
"name": "timesync-status",
57+
"description": "Show status of systemd-timesyncd"
58+
},
59+
{
60+
"name": "show-timesync",
61+
"description": "Show properties of systemd-timesyncd"
62+
}
63+
],
64+
"options": [
65+
{
66+
"name": [
67+
"-h",
68+
"--help"
69+
],
70+
"description": "Show this help message"
71+
},
72+
{
73+
"name": "--version",
74+
"description": "Show package version"
75+
},
76+
{
77+
"name": "--no-pager",
78+
"description": "Do not pipe output into a pager"
79+
},
80+
{
81+
"name": "--no-ask-password",
82+
"description": "Do not prompt for password"
83+
},
84+
{
85+
"name": [
86+
"-H",
87+
"--host"
88+
],
89+
"description": "Operate on remote HOST",
90+
"args": {
91+
"name": "HOST"
92+
}
93+
},
94+
{
95+
"name": [
96+
"-M",
97+
"--machine"
98+
],
99+
"description": "Operate on local CONTAINER",
100+
"args": {
101+
"name": "CONTAINER"
102+
}
103+
},
104+
{
105+
"name": "--adjust-system-clock",
106+
"description": "Adjust system clock when changing local RTC mode"
107+
},
108+
{
109+
"name": "--monitor",
110+
"description": "Monitor status of systemd-timesyncd"
111+
},
112+
{
113+
"name": [
114+
"-p",
115+
"--property"
116+
],
117+
"description": "Show only properties by this NAME",
118+
"args": {
119+
"name": "NAME"
120+
}
121+
},
122+
{
123+
"name": [
124+
"-a",
125+
"--all"
126+
],
127+
"description": "Show all properties"
128+
},
129+
{
130+
"name": "--value",
131+
"description": "Only show properties with values"
132+
}
133+
]
134+
}

command-signatures/src/generators/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ mod screen;
4141
mod ssh;
4242
mod tar;
4343
mod terraform;
44+
mod timedatectl;
4445
mod tmux;
4546
mod tmuxinator;
4647

@@ -86,6 +87,7 @@ pub fn dynamic_command_signature_data() -> HashMap<String, DynamicCompletionData
8687
kubecolor::generator(),
8788
kill::generator(),
8889
killall::generator(),
90+
timedatectl::generator(),
8991
tmuxinator::generator(),
9092
tmux::generator(),
9193
node::generator(),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use warp_completion_metadata::{
2+
CommandBuilder, CommandSignatureGenerators, Generator, GeneratorResultsCollector, Suggestion,
3+
};
4+
5+
pub fn generator() -> CommandSignatureGenerators {
6+
CommandSignatureGenerators::new("timedatectl").add_generator(
7+
"timezone_generator",
8+
Generator::script(
9+
CommandBuilder::single_command("timedatectl list-timezones"),
10+
|output| {
11+
output
12+
.trim()
13+
.lines()
14+
.map(|line| Suggestion::new(line.trim()))
15+
.collect_unordered_results()
16+
},
17+
),
18+
)
19+
}

0 commit comments

Comments
 (0)