Skip to content

Commit

Permalink
feat: refactor cli parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Shubharanshu Mahapatra <[email protected]>
  • Loading branch information
Shubhranshu153 committed Dec 3, 2024
1 parent 0c143a9 commit 9976ca9
Show file tree
Hide file tree
Showing 11 changed files with 1,510 additions and 1,069 deletions.
18 changes: 7 additions & 11 deletions cmd/finch/devcontainer_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
"github.com/docker/go-connections/nat"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/runfinch/finch/pkg/command"
)
Expand Down Expand Up @@ -111,15 +110,12 @@ func inspectContainerOutputHandler(cmd command.Command) error {
return err
}

func handleDockerCompatComposeVersion(cmdName string, nc nerdctlCommand, runArgs []string) error {
if cmdName == "compose" && nc.fc.DockerCompat && slices.Contains(runArgs, "version") {
ver := nc.systemDeps.Env("DOCKER_COMPOSE_VERSION")
if ver != "" {
logrus.Warn("Displaying docker compose version set as environment variable DOCKER_COMPOSE_VERSION...")
fmt.Println(ver)
return nil
}
return errors.New("DOCKER_COMPOSE_VERSION environment variable is not set")
func handleDockerCompatComposeVersion(nc nerdctlCommand) error {
ver := nc.systemDeps.Env("DOCKER_COMPOSE_VERSION")
if ver != "" {
logrus.Warn("Displaying docker compose version set as environment variable DOCKER_COMPOSE_VERSION...")
fmt.Println(ver)
return nil
}
return errors.New("")
return errors.New("DOCKER_COMPOSE_VERSION environment variable is not set")
}
25 changes: 19 additions & 6 deletions cmd/finch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,26 @@ func initializeNerdctlCommands(
nerdctlCommandCreator := newNerdctlCommandCreator(ncc, ecc, system.NewStdLib(), logger, fs, fc)
var allNerdctlCommands []*cobra.Command
for cmdName, cmdDescription := range nerdctlCmds {
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.create(cmdName, cmdDescription))
}

if fc != nil && fc.DockerCompat {
for cmdName, cmdDescription := range dockerCompatCmds {
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.create(cmdName, cmdDescription))
if fc != nil && fc.DockerCompat {
switch cmdName {
case "build":
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.createDockerCompatBuildCmd())
continue
case "image":
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.createDockerCompatImageCmd())
continue
case "inspect":
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.createDockerCompatInspectCmd())
continue
case "run":
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.createDockerCompatRunCmd())
continue
case "compose":
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.createDockerCompatComposeCmd())
continue
}
}
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.create(cmdName, cmdDescription))
}

return allNerdctlCommands
Expand Down
Loading

0 comments on commit 9976ca9

Please sign in to comment.