Skip to content

Commit 4ccc299

Browse files
authored
refactor: expose CLI main function externally (transitional) (#11)
1 parent f23675b commit 4ccc299

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

cmd/azldev/azldev.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,9 @@
44
package main
55

66
import (
7-
"os"
8-
9-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev"
10-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/advanced"
11-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/component"
12-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/config"
13-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/docs"
14-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/image"
15-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/project"
16-
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/version"
7+
"github.com/microsoft/azure-linux-dev-tools/pkg/app/azldev_cli"
178
)
189

1910
func main() {
20-
// Instantiate the main CLI app instance.
21-
app := InstantiateApp()
22-
23-
// Execute! We'll get back an exit code that we will exit with.
24-
ret := app.Execute(os.Args[1:])
25-
26-
os.Exit(ret)
27-
}
28-
29-
// Constructs a new instance of the main CLI application, with all subcommands registered.
30-
func InstantiateApp() *azldev.App {
31-
// Instantiate the main CLI application.
32-
app := azldev.NewApp(azldev.DefaultFileSystemFactory(), azldev.DefaultOSEnvFactory())
33-
34-
// Give top level command packages an opportunity to register their commands (or in some cases,
35-
// request post-init callbacks).
36-
advanced.OnAppInit(app)
37-
component.OnAppInit(app)
38-
config.OnAppInit(app)
39-
docs.OnAppInit(app)
40-
image.OnAppInit(app)
41-
project.OnAppInit(app)
42-
version.OnAppInit(app)
43-
44-
return app
11+
azldev_cli.Main()
4512
}

pkg/app/azldev_cli/azldev.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
package azldev_cli
5+
6+
import (
7+
"os"
8+
9+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev"
10+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/advanced"
11+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/component"
12+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/config"
13+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/docs"
14+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/image"
15+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/project"
16+
"github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/cmds/version"
17+
)
18+
19+
func Main() {
20+
// Instantiate the main CLI app instance.
21+
app := InstantiateApp()
22+
23+
// Execute! We'll get back an exit code that we will exit with.
24+
ret := app.Execute(os.Args[1:])
25+
26+
os.Exit(ret)
27+
}
28+
29+
// Constructs a new instance of the main CLI application, with all subcommands registered.
30+
func InstantiateApp() *azldev.App {
31+
// Instantiate the main CLI application.
32+
app := azldev.NewApp(azldev.DefaultFileSystemFactory(), azldev.DefaultOSEnvFactory())
33+
34+
// Give top level command packages an opportunity to register their commands (or in some cases,
35+
// request post-init callbacks).
36+
advanced.OnAppInit(app)
37+
component.OnAppInit(app)
38+
config.OnAppInit(app)
39+
docs.OnAppInit(app)
40+
image.OnAppInit(app)
41+
project.OnAppInit(app)
42+
version.OnAppInit(app)
43+
44+
return app
45+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
package main_test
4+
package azldev_cli_test
55

66
import (
77
"testing"
88

9-
main "github.com/microsoft/azure-linux-dev-tools/cmd/azldev"
9+
azldev_cli "github.com/microsoft/azure-linux-dev-tools/pkg/app/azldev_cli"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
)
1313

1414
func TestInstantiateApp(t *testing.T) {
15-
app := main.InstantiateApp()
15+
app := azldev_cli.InstantiateApp()
1616
if assert.NotNil(t, app) {
1717
topLevelCommandNames, err := app.CommandNames()
1818
require.NoError(t, err)

0 commit comments

Comments
 (0)