Skip to content

Commit 3c75b40

Browse files
Fix cli table not properly aligned (#516)
Co-authored-by: Luca Rinaldi <lucarin@protonmail.com>
1 parent 27d54d6 commit 3c75b40

File tree

26 files changed

+460
-384
lines changed

26 files changed

+460
-384
lines changed

.licenses/arduino-app-cli/NOTICE

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -114300,6 +114300,56 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114300114300
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
114301114301
THE SOFTWARE.
114302114302

114303+
*****
114304+
github.com/jedib0t/go-pretty/v6/table@v6.6.8
114305+
114306+
MIT License
114307+
114308+
Copyright (c) 2018 jedib0t
114309+
114310+
Permission is hereby granted, free of charge, to any person obtaining a copy
114311+
of this software and associated documentation files (the "Software"), to deal
114312+
in the Software without restriction, including without limitation the rights
114313+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
114314+
copies of the Software, and to permit persons to whom the Software is
114315+
furnished to do so, subject to the following conditions:
114316+
114317+
The above copyright notice and this permission notice shall be included in all
114318+
copies or substantial portions of the Software.
114319+
114320+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
114321+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114322+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
114323+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
114324+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114325+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
114326+
SOFTWARE.
114327+
114328+
*****
114329+
github.com/jedib0t/go-pretty/v6/text@v6.6.8
114330+
114331+
MIT License
114332+
114333+
Copyright (c) 2018 jedib0t
114334+
114335+
Permission is hereby granted, free of charge, to any person obtaining a copy
114336+
of this software and associated documentation files (the "Software"), to deal
114337+
in the Software without restriction, including without limitation the rights
114338+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
114339+
copies of the Software, and to permit persons to whom the Software is
114340+
furnished to do so, subject to the following conditions:
114341+
114342+
The above copyright notice and this permission notice shall be included in all
114343+
copies or substantial portions of the Software.
114344+
114345+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
114346+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114347+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
114348+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
114349+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114350+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
114351+
SOFTWARE.
114352+
114303114353
*****
114304114354
github.com/jonboulle/clockwork@v0.5.0
114305114355

@@ -140597,7 +140647,7 @@ Apache License
140597140647
limitations under the License.
140598140648

140599140649
*****
140600-
github.com/rivo/uniseg@v0.4.4
140650+
github.com/rivo/uniseg@v0.4.7
140601140651

140602140652
MIT License
140603140653

@@ -239012,37 +239062,6 @@ Apache License
239012239062
See the License for the specific language governing permissions and
239013239063
limitations under the License.
239014239064

239015-
*****
239016-
mkuznets.com/go/tabwriter@v0.1.2
239017-
239018-
Copyright (c) 2009 The Go Authors. All rights reserved.
239019-
239020-
Redistribution and use in source and binary forms, with or without
239021-
modification, are permitted provided that the following conditions are
239022-
met:
239023-
239024-
* Redistributions of source code must retain the above copyright
239025-
notice, this list of conditions and the following disclaimer.
239026-
* Redistributions in binary form must reproduce the above
239027-
copyright notice, this list of conditions and the following disclaimer
239028-
in the documentation and/or other materials provided with the
239029-
distribution.
239030-
* Neither the name of Google Inc. nor the names of its
239031-
contributors may be used to endorse or promote products derived from
239032-
this software without specific prior written permission.
239033-
239034-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
239035-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
239036-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
239037-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
239038-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
239039-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
239040-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239041-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
239042-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
239043-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
239044-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
239045-
239046239065
*****
239047239066
sigs.k8s.io/json@v0.0.0-20241010143419-9aa6b5e7a4b3
239048239067

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: github.com/jedib0t/go-pretty/v6/table
3+
version: v6.6.8
4+
type: go
5+
summary:
6+
homepage: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/table
7+
license: mit
8+
licenses:
9+
- sources: v6@v6.6.8/LICENSE
10+
text: |
11+
MIT License
12+
13+
Copyright (c) 2018 jedib0t
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy
16+
of this software and associated documentation files (the "Software"), to deal
17+
in the Software without restriction, including without limitation the rights
18+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
copies of the Software, and to permit persons to whom the Software is
20+
furnished to do so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE.
32+
notices: []
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: github.com/jedib0t/go-pretty/v6/text
3+
version: v6.6.8
4+
type: go
5+
summary:
6+
homepage: https://pkg.go.dev/github.com/jedib0t/go-pretty/v6/text
7+
license: mit
8+
licenses:
9+
- sources: v6@v6.6.8/LICENSE
10+
text: |
11+
MIT License
12+
13+
Copyright (c) 2018 jedib0t
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy
16+
of this software and associated documentation files (the "Software"), to deal
17+
in the Software without restriction, including without limitation the rights
18+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
copies of the Software, and to permit persons to whom the Software is
20+
furnished to do so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE.
32+
notices: []

.licenses/arduino-app-cli/go/github.com/rivo/uniseg.dep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: github.com/rivo/uniseg
3-
version: v0.4.4
3+
version: v0.4.7
44
type: go
55
summary: Package uniseg implements Unicode Text Segmentation, Unicode Line Breaking,
66
and string width calculation for monospace fonts.

.licenses/arduino-app-cli/go/mkuznets.com/go/tabwriter.dep.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

cmd/arduino-app-cli/app/list.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,34 @@ package app
22

33
import (
44
"context"
5+
"strings"
56

7+
"github.com/jedib0t/go-pretty/v6/table"
68
"github.com/spf13/cobra"
79

10+
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/cmdutil"
811
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
9-
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/results"
1012
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1113
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
14+
"github.com/bcmi-labs/orchestrator/pkg/tablestyle"
1215
)
1316

1417
func newListCmd() *cobra.Command {
15-
var jsonFormat bool
18+
var showBrokenApps bool
1619

1720
cmd := &cobra.Command{
1821
Use: "list",
1922
Short: "List all running Python apps",
2023
Run: func(cmd *cobra.Command, args []string) {
21-
listHandler(cmd.Context())
24+
listHandler(cmd.Context(), showBrokenApps)
2225
},
2326
}
2427

25-
cmd.Flags().BoolVarP(&jsonFormat, "json", "", false, "Output the list in json format")
28+
cmd.Flags().BoolVarP(&showBrokenApps, "show-broken-apps", "", false, "Output a list of broken apps")
2629
return cmd
2730
}
2831

29-
func listHandler(ctx context.Context) {
32+
func listHandler(ctx context.Context, showBrokenApps bool) {
3033
res, err := orchestrator.ListApps(ctx,
3134
servicelocator.GetDockerClient(),
3235
orchestrator.ListAppRequest{
@@ -39,8 +42,44 @@ func listHandler(ctx context.Context) {
3942
feedback.Fatal(err.Error(), feedback.ErrGeneric)
4043
}
4144

42-
feedback.PrintResult(results.AppListResult{
43-
Apps: res.Apps,
44-
BrokenApps: res.BrokenApps,
45+
feedback.PrintResult(appListResult{
46+
Apps: res.Apps,
47+
BrokenApps: res.BrokenApps,
48+
showBrokenApps: showBrokenApps,
4549
})
4650
}
51+
52+
type appListResult struct {
53+
Apps []orchestrator.AppInfo `json:"apps"`
54+
BrokenApps []orchestrator.BrokenAppInfo `json:"brokenApps"`
55+
showBrokenApps bool
56+
}
57+
58+
func (r appListResult) String() string {
59+
t := table.NewWriter()
60+
t.SetStyle(tablestyle.CustomCleanStyle)
61+
t.AppendHeader(table.Row{"ID", "NAME", "ICON", "STATUS", "EXAMPLE"})
62+
63+
for _, app := range r.Apps {
64+
t.AppendRow(table.Row{
65+
cmdutil.IDToAlias(app.ID),
66+
app.Name,
67+
app.Icon,
68+
app.Status,
69+
app.Example,
70+
})
71+
}
72+
if r.showBrokenApps && len(r.BrokenApps) > 0 {
73+
var b strings.Builder
74+
_, _ = b.WriteString("\nBROKEN APPS\n")
75+
for _, app := range r.BrokenApps {
76+
b.WriteString(app.Name + ": " + app.Error + "\n")
77+
}
78+
return t.Render() + "\n" + b.String()
79+
}
80+
return t.Render()
81+
}
82+
83+
func (r appListResult) Data() interface{} {
84+
return r
85+
}

cmd/arduino-app-cli/app/new.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package app
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/spf13/cobra"
78

8-
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/results"
99
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1010
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
1111
)
@@ -58,7 +58,7 @@ func createHandler(ctx context.Context, name string, icon string, noPython, noSk
5858
}
5959
dst := resp.ID.ToPath()
6060

61-
feedback.PrintResult(results.CreateAppResult{
61+
feedback.PrintResult(createAppResult{
6262
Result: "ok",
6363
Message: "App created successfully",
6464
Path: dst.String(),
@@ -75,11 +75,25 @@ func createHandler(ctx context.Context, name string, icon string, noPython, noSk
7575
feedback.Fatal(err.Error(), feedback.ErrGeneric)
7676
return nil
7777
}
78-
feedback.PrintResult(results.CreateAppResult{
78+
feedback.PrintResult(createAppResult{
7979
Result: "ok",
8080
Message: "App created successfully",
8181
Path: resp.ID.ToPath().String(),
8282
})
8383
}
8484
return nil
8585
}
86+
87+
type createAppResult struct {
88+
Path string `json:"path"`
89+
Message string `json:"message"`
90+
Result string `json:"result"`
91+
}
92+
93+
func (r createAppResult) String() string {
94+
return fmt.Sprintf("%s: %s (%s)", r.Message, r.Path, r.Result)
95+
}
96+
97+
func (r createAppResult) Data() interface{} {
98+
return r
99+
}

cmd/arduino-app-cli/app/start.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/completion"
1010
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/internal/servicelocator"
11-
"github.com/bcmi-labs/orchestrator/cmd/arduino-app-cli/results"
1211
"github.com/bcmi-labs/orchestrator/cmd/feedback"
1312
"github.com/bcmi-labs/orchestrator/internal/orchestrator"
1413
"github.com/bcmi-labs/orchestrator/internal/orchestrator/app"
@@ -56,11 +55,25 @@ func startHandler(ctx context.Context, app app.ArduinoApp) error {
5655
}
5756
}
5857
outputResult := getResult()
59-
feedback.PrintResult(results.StartAppResult{
58+
feedback.PrintResult(startAppResult{
6059
AppName: app.Name,
6160
Status: "started",
6261
Output: outputResult,
6362
})
6463

6564
return nil
6665
}
66+
67+
type startAppResult struct {
68+
AppName string `json:"appName"`
69+
Status string `json:"status"`
70+
Output *feedback.OutputStreamsResult `json:"output,omitempty"`
71+
}
72+
73+
func (r startAppResult) String() string {
74+
return fmt.Sprintf("✓ App %q started successfully", r.AppName)
75+
}
76+
77+
func (r startAppResult) Data() interface{} {
78+
return r
79+
}

0 commit comments

Comments
 (0)