Skip to content

Commit a2874d5

Browse files
committed
kt: Add list-kernels command
It will show all the kernels we support. The implementation is under kt/commands/list-kernels folder. To keep things cleaner, the actual logic is done in impl.py, while command.py is used for the click interface, like argument and helper logic. Signed-off-by: Roxana Nicolescu <rnicolescu@ciq.com>
1 parent adef27f commit a2874d5

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

bin/kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import logging
44

55
import click
66

7+
from kt.commands.list_kernels.command import list_kernels
8+
79
epilog = """
810
Base of all tooling used for kernel development.
911
@@ -19,6 +21,7 @@ def cli():
1921
def main():
2022
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
2123

24+
cli.add_command(list_kernels)
2225
cli()
2326

2427

kt/KT.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,48 @@ if the base_path is ~/ciq.
100100

101101
The KernelInfo dataclass will be used later when we set up each kernel working
102102
environment.
103+
104+
## Commands
105+
106+
Make sure kt is reachable from anywhere by adding it's location to PATH.
107+
Example
108+
```
109+
export PATH=$HOME/ciq/kernel-src-tree-tools/bin:$PATH
110+
```
111+
If you are unsure how to use kt, just run it with --help.
112+
Example:
113+
```
114+
$ kt --help
115+
```
116+
117+
Run --help for subcommands as well.
118+
119+
Autocompletion works relatively well. Make sure it's enabled for your shell.
120+
Check the official doc for [click](https://click.palletsprojects.com/en/stable/shell-completion/#enabling-completion)
121+
Example for zsh:
122+
```
123+
eval "$(_KT_COMPLETE=zsh_source kt)"
124+
```
125+
126+
A command implementation is under ```kt/commands/<command>``` folder.
127+
To keep things cleaner, the actual logic is done in impl.py,
128+
while command.py is used for the click interface, like argument and helper logic.
129+
130+
### kt list-kernels
131+
It shows the kernels we currently maintain. The data is taken from
132+
KernelsInfo object which represents the kernels.yaml file in kt/data.
133+
134+
Example:
135+
136+
```
137+
$ kt list-kernels
138+
cbr-7.9
139+
fips-8.10
140+
fips-8.6
141+
fips-9.2
142+
fipslegacy-8.6
143+
lts-8.6
144+
lts-8.8
145+
lts-9.2
146+
lts-9.4
147+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import click
2+
3+
from kt.commands.list_kernels.impl import main
4+
5+
epilog = """
6+
It list all the kernels we currently maintain.
7+
8+
Example:
9+
10+
\b
11+
$ kt list-kernels
12+
13+
"""
14+
15+
16+
@click.command(epilog=epilog)
17+
def list_kernels():
18+
main()

kt/commands/list_kernels/impl.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from kt.ktlib.config import Config
2+
from kt.ktlib.kernels import KernelsInfo
3+
4+
5+
def main():
6+
config = Config.load()
7+
kernels = KernelsInfo.from_yaml(config=config).kernels
8+
for k in sorted(kernels):
9+
print(k)

0 commit comments

Comments
 (0)