Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
8cb39ce5
Commit
8cb39ce5
authored
Jun 28, 2016
by
Adam Reese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ref(cmd): refactor out globals and init()
parent
d32c20fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
34 deletions
+44
-34
list.go
cmd/helm/list.go
+44
-34
No files found.
cmd/helm/list.go
View file @
8cb39ce5
...
...
@@ -18,6 +18,8 @@ package main
import
(
"fmt"
"io"
"os"
"strings"
"github.com/gosuri/uitable"
...
...
@@ -52,51 +54,59 @@ server's default, which may be much higher than 256. Pairing the '--max'
flag with the '--offset' flag allows you to page through results.
`
var
listCommand
=
&
cobra
.
Command
{
Use
:
"list [flags] [FILTER]"
,
Short
:
"list releases"
,
Long
:
listHelp
,
RunE
:
listCmd
,
Aliases
:
[]
string
{
"ls"
},
PersistentPreRunE
:
setupConnection
,
type
lister
struct
{
long
bool
max
int
offset
string
byDate
bool
sortDesc
bool
out
io
.
Writer
}
var
(
listLong
bool
listMax
int
listOffset
string
listByDate
bool
listSortDesc
bool
)
func
newListCmd
(
out
io
.
Writer
)
*
cobra
.
Command
{
list
:=
&
lister
{
out
:
out
,
}
cmd
:=
&
cobra
.
Command
{
Use
:
"list [flags] [FILTER]"
,
Short
:
"list releases"
,
Long
:
listHelp
,
Aliases
:
[]
string
{
"ls"
},
PersistentPreRunE
:
setupConnection
,
RunE
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
return
list
.
run
(
args
)
},
}
f
:=
cmd
.
Flags
()
f
.
BoolVarP
(
&
list
.
long
,
"long"
,
"l"
,
false
,
"output long listing format"
)
f
.
BoolVarP
(
&
list
.
byDate
,
"date"
,
"d"
,
false
,
"sort by release date"
)
f
.
BoolVarP
(
&
list
.
sortDesc
,
"reverse"
,
"r"
,
false
,
"reverse the sort order"
)
f
.
IntVarP
(
&
list
.
max
,
"max"
,
"m"
,
256
,
"maximum number of releases to fetch"
)
f
.
StringVarP
(
&
list
.
offset
,
"offset"
,
"o"
,
""
,
"the next release name in the list, used to offset from start value"
)
return
cmd
}
func
init
()
{
f
:=
listCommand
.
Flags
()
f
.
BoolVarP
(
&
listLong
,
"long"
,
"l"
,
false
,
"output long listing format"
)
f
.
BoolVarP
(
&
listByDate
,
"date"
,
"d"
,
false
,
"sort by release date"
)
f
.
BoolVarP
(
&
listSortDesc
,
"reverse"
,
"r"
,
false
,
"reverse the sort order"
)
f
.
IntVarP
(
&
listMax
,
"max"
,
"m"
,
256
,
"maximum number of releases to fetch"
)
f
.
StringVarP
(
&
listOffset
,
"offset"
,
"o"
,
""
,
"the next release name in the list, used to offset from start value"
)
RootCommand
.
AddCommand
(
listCommand
)
RootCommand
.
AddCommand
(
newListCmd
(
os
.
Stdout
))
}
func
listCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
func
(
l
*
lister
)
run
(
args
[]
string
)
error
{
var
filter
string
if
len
(
args
)
>
0
{
filter
=
strings
.
Join
(
args
,
" "
)
}
sortBy
:=
services
.
ListSort_NAME
if
l
istB
yDate
{
if
l
.
b
yDate
{
sortBy
=
services
.
ListSort_LAST_RELEASED
}
sortOrder
:=
services
.
ListSort_ASC
if
l
istS
ortDesc
{
if
l
.
s
ortDesc
{
sortOrder
=
services
.
ListSort_DESC
}
res
,
err
:=
helm
.
ListReleases
(
l
istMax
,
listO
ffset
,
sortBy
,
sortOrder
,
filter
)
res
,
err
:=
helm
.
ListReleases
(
l
.
max
,
l
.
o
ffset
,
sortBy
,
sortOrder
,
filter
)
if
err
!=
nil
{
return
prettyError
(
err
)
}
...
...
@@ -106,21 +116,23 @@ func listCmd(cmd *cobra.Command, args []string) error {
}
if
res
.
Next
!=
""
{
fmt
.
Printf
(
"
\t
next: %s"
,
res
.
Next
)
fmt
.
Fprintf
(
l
.
out
,
"
\t
next: %s"
,
res
.
Next
)
}
rels
:=
res
.
Releases
if
listLong
{
return
formatList
(
rels
)
if
l
.
long
{
fmt
.
Fprintln
(
l
.
out
,
formatList
(
rels
))
return
nil
}
for
_
,
r
:=
range
rels
{
fmt
.
Println
(
r
.
Name
)
fmt
.
Fprintln
(
l
.
out
,
r
.
Name
)
}
return
nil
}
func
formatList
(
rels
[]
*
release
.
Release
)
error
{
func
formatList
(
rels
[]
*
release
.
Release
)
string
{
table
:=
uitable
.
New
()
table
.
MaxColWidth
=
30
table
.
AddRow
(
"NAME"
,
"UPDATED"
,
"STATUS"
,
"CHART"
)
...
...
@@ -130,7 +142,5 @@ func formatList(rels []*release.Release) error {
s
:=
r
.
Info
.
Status
.
Code
.
String
()
table
.
AddRow
(
r
.
Name
,
t
,
s
,
c
)
}
fmt
.
Println
(
table
)
return
nil
return
table
.
String
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment