-
Notifications
You must be signed in to change notification settings - Fork 699
limactl help and info flag should show available plugins #4009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
limactl help and info flag should show available plugins #4009
Conversation
9993a6e
to
e012aa1
Compare
e012aa1
to
6854c86
Compare
6854c86
to
51673df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the docs changes, but here is some feedback on the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs review
f2fea51
to
2d073bc
Compare
2d073bc
to
ff781c8
Compare
BATS failing
https://github.com/lima-vm/lima/actions/runs/17775630264/job/50573056648?pr=4009 |
ff781c8
to
5a7b1fa
Compare
Signed-off-by: olalekan odukoya <[email protected]>
5a7b1fa
to
79ef8e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly fine, but I still have some stylistic feedback, and some minor issues.
@@ -51,7 +51,7 @@ func main() { | |||
rootCmd := newApp() | |||
if err := executeWithPluginSupport(rootCmd, os.Args[1:]); err != nil { | |||
server.StopAllExternalDrivers() | |||
handleExitError(err) | |||
usrlocalsharelima.HandleExitError(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usrlocalsharelima
is kind of an unexpected place for this function. I would move it maybe to its own file in pkg/osutil/exit.go
.
But this is nitpicking, unless there are other reasons to update the PR once more, this can also be fixed up later.
@@ -51,7 +51,7 @@ func main() { | |||
rootCmd := newApp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit-picking: This whole block could be written like this:
rootCmd := newApp()
err := executeWithPluginSupport(rootCmd, os.Args[1:])
server.StopAllExternalDrivers()
usrlocalsharelima.HandleExitError(err)
if err != nil {
logrus.Fatal(err)
}
if err := rootCmd.ParseFlags(args); err == nil { | ||
if debug, _ := rootCmd.Flags().GetBool("debug"); debug { | ||
logrus.SetLevel(logrus.DebugLevel) | ||
debugutil.Debug = true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It bothers me that this code block exists in 2 places. Can't it be called early enough that it covers both execution branches?
I think this here might be enough, and you can delete the copy in the PersistentPreRun command?
var dirs []string | ||
|
||
selfDirs := usrlocalsharelima.SelfDirs() | ||
dirs = append(dirs, selfDirs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be just
var dirs []string | |
selfDirs := usrlocalsharelima.SelfDirs() | |
dirs = append(dirs, selfDirs...) | |
dirs := usrlocalsharelima.SelfDirs() |
dirs := getPluginDirectories() | ||
|
||
for _, dir := range dirs { | ||
pluginsInDir := scanDirectory(dir) | ||
for _, plugin := range pluginsInDir { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a personal preference, but I prefer to avoid temp variables that are only used once, unless they are necessary to keep the expressions short. But I find this easier to read:
dirs := getPluginDirectories() | |
for _, dir := range dirs { | |
pluginsInDir := scanDirectory(dir) | |
for _, plugin := range pluginsInDir { | |
for _, dir := range getPluginDirectories() { | |
for _, plugin := range scanDirectory(dir) { |
Of course this only works because the functions don't return an error.
if runtime.GOOS == "windows" { | ||
ext := filepath.Ext(path) | ||
return isWindowsExecutableExt(ext) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this code is needed.
The file extension is only needed when you run a command without an extension. E.g. when you run tar
Windows will try each extension from PATHEXT
in turn to find an executable: tar.exe
, tar.bat
, etc.
But Windows will execute any command that exists as-is, regardless of the extension:
C:\Users\suse>tar
tar: Must specify one of -c, -r, -t, -u, -x
C:\Users\suse>copy C:\Windows\System32\tar.exe hello.world
1 file(s) copied.
C:\Users\suse>hello.world
hello.world: Must specify one of -c, -r, -t, -u, -x
So I think I would just remove this block completely. We want to strip the common extensions from the plugin name for the --help
output, but here we don't really care.
} | ||
|
||
if !strings.HasPrefix(string(content), "#!") { | ||
logrus.Debugf("Plugin %s: not a script file, skipping description extraction", filepath.Base(path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the debug log should always include the full path name. This is for debugging issues, normal users will not see the output because they don't use --debug
.
logrus.Debugf("Plugin %s: not a script file, skipping description extraction", filepath.Base(path)) | |
logrus.Debugf("Plugin %s: not a script file, skipping description extraction", path) |
Same for the next error below.
var descs []string | ||
for _, match := range matches { | ||
if len(match) > 1 { | ||
descs = append(descs, strings.TrimSpace(match[1])) | ||
} | ||
} | ||
|
||
if len(descs) == 0 { | ||
return "" | ||
} | ||
|
||
mergedDesc := descs[0] | ||
for _, line := range descs[1:] { | ||
mergedDesc += "\n" + strings.Repeat(" ", 22) + line | ||
} | ||
|
||
logrus.Debugf("Plugin %s: extracted merged description from script:\n%q", filepath.Base(path), mergedDesc) | ||
return mergedDesc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should ignore everything but the first match. And you definitely should not include multi-line formatting in the description here; that would have to be done at the presentation layer. But I think we should simply recommend to use short, one-line descriptions.
So the whole block should be just return matches[0]
and that's it.
- `limactl plugins` plugin mechanism (see [CLI plugins](../config/plugin/cli)) | ||
- `limactl-*` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be in the previous block ("The following features are experimental and subject to change:") under the "External drivers:" line, and look like this:
- `limactl plugins` plugin mechanism (see [CLI plugins](../config/plugin/cli)) | |
- `limactl-*` | |
- `limactl plugins:` plugin mechanism (see [CLI plugins](../config/plugin/cli)) |
There are no specific commands to list down here because plugins would be invoked just like a builtin command, and we can't list limactl *
here. 😄
``` | ||
|
||
**Format Requirements:** | ||
- Only files beginning with a shebang (`#!`) are treated as scripts, and their <limactl-desc> lines will be extracted as the plugin description i.e Must contain exactly `<limactl-desc>Description text</limactl-desc>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tag needs to be quoted here:
- Only files beginning with a shebang (`#!`) are treated as scripts, and their <limactl-desc> lines will be extracted as the plugin description i.e Must contain exactly `<limactl-desc>Description text</limactl-desc>` | |
- Only files beginning with a shebang (`#!`) are treated as scripts, and their `<limactl-desc>` lines will be extracted as the plugin description i.e Must contain exactly `<limactl-desc>Description text</limactl-desc>` |
Fixes #3608 (comment)