Skip to content

Commit

Permalink
chore: export core package and transition GetCommands to its own pack…
Browse files Browse the repository at this point in the history
…age (scaleway#4093)
  • Loading branch information
remyleone authored Sep 9, 2024
1 parent a774083 commit 7f069ea
Show file tree
Hide file tree
Showing 390 changed files with 365 additions and 363 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ RUN go mod download

COPY scripts/ scripts/
COPY cmd/ cmd/
COPY core/ core/
COPY commands/ commands/
COPY internal/ internal/
COPY .git/ .git/

Expand Down
6 changes: 3 additions & 3 deletions cmd/scw-doc-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"os"

"github.com/scaleway/scaleway-cli/v2/commands"
"github.com/scaleway/scaleway-cli/v2/internal/docgen"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
)

// This command is used to generate markdown documentation for each commands (custom or generated) of the CLI
func main() {
commands := namespaces.GetCommands()
cmds := commands.GetCommands()

outDir := flag.String("outdir", "./docs/commands", "Directory where markdown will be created")
flag.Parse()
Expand All @@ -25,7 +25,7 @@ func main() {
panic(fmt.Errorf("outdir %s must be a valid directory", *outDir))
}

err = docgen.GenerateDocs(commands, *outDir)
err = docgen.GenerateDocs(cmds, *outDir)
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/scw-qa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"strings"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
"github.com/scaleway/scaleway-cli/v2/commands"
"github.com/scaleway/scaleway-cli/v2/internal/qa"
"github.com/scaleway/scaleway-cli/v2/internal/tabwriter"
"github.com/scaleway/scaleway-cli/v2/internal/terminal"
)

func main() {
commands := namespaces.GetCommands()
errors := qa.LintCommands(commands)
cmds := commands.GetCommands()
errors := qa.LintCommands(cmds)

fmt.Println(terminal.Style("Errors:", color.Bold))
for _, err := range errors {
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw-wasm-tester/human.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"syscall/js"

"github.com/hashicorp/go-version"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/scw-wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"syscall/js"

"github.com/hashicorp/go-version"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
"github.com/scaleway/scaleway-cli/v2/internal/wasm"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/scw-wasm/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"syscall/js"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
"github.com/scaleway/scaleway-cli/v2/internal/wasm"
)
Expand Down
6 changes: 3 additions & 3 deletions cmd/scw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/hashicorp/go-version"
"github.com/mattn/go-colorable"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
"github.com/scaleway/scaleway-cli/v2/commands"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/platform/terminal"
"github.com/scaleway/scaleway-cli/v2/internal/sentry"
"github.com/scaleway/scaleway-sdk-go/scw"
Expand Down Expand Up @@ -78,7 +78,7 @@ func mainNoExit() int {

exitCode, _, _ := core.Bootstrap(&core.BootstrapConfig{
Args: os.Args,
Commands: namespaces.GetCommands(),
Commands: commands.GetCommands(),
BuildInfo: buildInfo,
Stdout: colorable.NewColorableStdout(),
Stderr: colorable.NewColorableStderr(),
Expand Down
10 changes: 5 additions & 5 deletions cmd/scw/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"strings"
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
"github.com/scaleway/scaleway-cli/v2/commands"
"github.com/scaleway/scaleway-cli/v2/core"
)

func Test_MainUsage(t *testing.T) {
t.Run("usage", core.Test(&core.TestConfig{
Commands: namespaces.GetCommands(),
Commands: commands.GetCommands(),
Cmd: "scw -h",
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
Expand All @@ -27,15 +27,15 @@ func Test_AllUsage(t *testing.T) {
"autocomplete script": true,
}

for _, cmd := range namespaces.GetCommands().GetAll() {
for _, cmd := range commands.GetCommands().GetAll() {
commandLine := cmd.GetCommandLine("scw")
commandLine = strings.TrimPrefix(commandLine, "scw ")
if _, exists := excludedCommands[commandLine]; exists || cmd.Hidden {
continue
}

t.Run(commandLine+" usage", core.Test(&core.TestConfig{
Commands: namespaces.GetCommands(),
Commands: commands.GetCommands(),
Cmd: "scw " + commandLine + " -h",
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
Expand Down
6 changes: 3 additions & 3 deletions cmd/scw/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"testing"
"text/template"

"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
"github.com/scaleway/scaleway-cli/v2/commands"
)

func Test_WebValidateTemplates(t *testing.T) {
cmds := namespaces.GetCommands()
cmds := commands.GetCommands()

// Test that web urls are valid templates
type failedTemplate struct {
Expand All @@ -37,7 +37,7 @@ func Test_WebValidateTemplates(t *testing.T) {
}

func Test_WebValidateTemplatesVariables(t *testing.T) {
cmds := namespaces.GetCommands()
cmds := commands.GetCommands()

// Test that web urls are valid templates
type failedTemplate struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/namespaces/get_commands.go → commands/commands.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package namespaces
package commands

import (
"os"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
accountv3 "github.com/scaleway/scaleway-cli/v2/internal/namespaces/account/v3"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/alias"
applesilicon "github.com/scaleway/scaleway-cli/v2/internal/namespaces/applesilicon/v1alpha1"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/alias_test.go → core/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/alias"
"github.com/scaleway/scaleway-cli/v2/internal/core"
)

func TestCommandMatchAlias(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/arg_specs_test.go → core/arg_specs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func TestOneOf(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/platform/terminal"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/stretchr/testify/assert"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/bootstrap_test.go → core/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/args"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/alecthomas/assert"
"github.com/hashicorp/go-version"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/args"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/stretchr/testify/require"
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/checks_test.go → core/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
iam "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core_test
import (
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func Test_UnknownCommand(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

type ServerColor string
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"
"time"

"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/args"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/stretchr/testify/assert"
)

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func Test_CombineCommandInterceptor(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/default_test.go → core/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/args"
"github.com/scaleway/scaleway-cli/v2/internal/core"
)

func Test_ApplyDefaultValues(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/printer_test.go → core/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func Test_CorePrinter(t *testing.T) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/reflect_test.go → core/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-sdk-go/scw"
)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/result_test.go → core/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package core_test
import (
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/shell_test.go → core/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func TestShell_OptionToArgSpecName(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/testing_test.go → core/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func TestGoldenIgnoreLines(t *testing.T) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/core/validate_test.go → core/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/args"
"github.com/scaleway/scaleway-cli/v2/internal/core"
)

type Element struct {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"text/template"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

type tplData struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package e2e_test
import (
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/test/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/human_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package e2e_test
import (
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/test/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/sdk_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/alecthomas/assert"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/test/v1"
sdktest "github.com/scaleway/scaleway-sdk-go/api/test/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/editor/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package editor

import (
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

var LongDescription = `This command starts your default editor to edit a marshaled version of your resource
Expand Down
2 changes: 1 addition & 1 deletion internal/namespaces/account/v3/account_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"reflect"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-sdk-go/api/account/v3"
"github.com/scaleway/scaleway-sdk-go/scw"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/namespaces/account/v3/custom.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package account

import (
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/core"
)

func GetCommands() *core.Commands {
Expand Down
Loading

0 comments on commit 7f069ea

Please sign in to comment.