70 строки
1.7 KiB
Go
70 строки
1.7 KiB
Go
/*
|
|
* Copyright © 2022 Docker, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/atomist-skills/go-skill"
|
|
|
|
"github.com/docker/cli/cli-plugins/manager"
|
|
"github.com/docker/cli/cli-plugins/plugin"
|
|
"github.com/docker/cli/cli/command"
|
|
cliflags "github.com/docker/cli/cli/flags"
|
|
"github.com/docker/index-cli-plugin/commands"
|
|
"github.com/docker/index-cli-plugin/internal"
|
|
)
|
|
|
|
func runStandalone(cmd *command.DockerCli) error {
|
|
if err := cmd.Initialize(cliflags.NewClientOptions()); err != nil {
|
|
return err
|
|
}
|
|
rootCmd := commands.NewRootCmd(os.Args[0], false, cmd)
|
|
return rootCmd.Execute()
|
|
}
|
|
|
|
func runPlugin(cmd *command.DockerCli) error {
|
|
rootCmd := commands.NewRootCmd("index", true, cmd)
|
|
return plugin.RunPlugin(cmd, rootCmd, manager.Metadata{
|
|
SchemaVersion: "0.1.0",
|
|
Vendor: "Docker Inc.",
|
|
Version: internal.FromBuild().Version,
|
|
})
|
|
}
|
|
|
|
func main() {
|
|
cmd, err := command.NewDockerCli()
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if plugin.RunningStandalone() {
|
|
err = runStandalone(cmd)
|
|
} else {
|
|
err = runPlugin(cmd)
|
|
}
|
|
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
skill.Log.Errorf("%s", err)
|
|
os.Exit(1)
|
|
}
|