mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 13:11:30 +00:00
Engine: builtin command 'commands' returns a list of registered commands
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -110,6 +111,12 @@ func New(root string) (*Engine, error) {
|
||||
Stderr: os.Stderr,
|
||||
Stdin: os.Stdin,
|
||||
}
|
||||
eng.Register("commands", func(job *Job) Status {
|
||||
for _, name := range eng.commands() {
|
||||
job.Printf("%s\n", name)
|
||||
}
|
||||
return StatusOK
|
||||
})
|
||||
// Copy existing global handlers
|
||||
for k, v := range globalHandlers {
|
||||
eng.handlers[k] = v
|
||||
@@ -121,6 +128,17 @@ func (eng *Engine) String() string {
|
||||
return fmt.Sprintf("%s|%s", eng.Root(), eng.id[:8])
|
||||
}
|
||||
|
||||
// Commands returns a list of all currently registered commands,
|
||||
// sorted alphabetically.
|
||||
func (eng *Engine) commands() []string {
|
||||
names := make([]string, 0, len(eng.handlers))
|
||||
for name := range eng.handlers {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
// Job creates a new job which can later be executed.
|
||||
// This function mimics `Command` from the standard os/exec package.
|
||||
func (eng *Engine) Job(name string, args ...string) *Job {
|
||||
|
||||
Reference in New Issue
Block a user