Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
5372a522
Unverified
Commit
5372a522
authored
5 years ago
by
Drew Bailey
Browse files
Options
Download
Email Patches
Plain Diff
properly format license output
parent
105345ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
command/license.go
+19
-25
command/license.go
command/license_get_test.go
+7
-4
command/license_get_test.go
command/license_put.go
+0
-3
command/license_put.go
with
26 additions
and
32 deletions
+26
-32
command/license.go
+
19
-
25
View file @
5372a522
...
...
@@ -24,20 +24,15 @@ For more detailed examples see:
https://www.nomadproject.io/docs/commands/license/
Install a new license from a file:
$ nomad license put
@nomad.license
$ nomad license put
<path>
Install a new license from stdin:
$ nomad license put -
Install a new license from a string:
$ nomad license put "<license blob>"
Retrieve the current license:
$ nomad license get
Reset the current license:
$ nomad license reset
`
return
strings
.
TrimSpace
(
helpText
)
}
...
...
@@ -53,21 +48,22 @@ func (l *LicenseCommand) Run(args []string) int {
}
func
OutputLicenseReply
(
ui
cli
.
Ui
,
resp
*
api
.
LicenseReply
)
int
{
var
validity
string
if
resp
.
Valid
{
ui
.
Output
(
"License is
valid"
)
outputLicenseInfo
(
ui
,
resp
.
License
,
false
)
validity
=
"
valid"
outputLicenseInfo
(
ui
,
resp
.
License
,
false
,
validity
)
return
0
}
else
if
resp
.
License
!=
nil
{
now
:=
time
.
Now
()
if
resp
.
License
.
ExpirationTime
.
Before
(
now
)
{
ui
.
Output
(
"License has
expired!"
)
outputLicenseInfo
(
ui
,
resp
.
License
,
true
)
validity
=
"
expired!"
outputLicenseInfo
(
ui
,
resp
.
License
,
true
,
validity
)
}
else
{
ui
.
Output
(
"License is
invalid!"
)
validity
=
"
invalid!"
for
_
,
warn
:=
range
resp
.
Warnings
{
ui
.
Output
(
fmt
.
Sprintf
(
" %s"
,
warn
))
}
outputLicenseInfo
(
ui
,
resp
.
License
,
false
)
outputLicenseInfo
(
ui
,
resp
.
License
,
false
,
validity
)
}
return
1
}
else
{
...
...
@@ -78,28 +74,26 @@ func OutputLicenseReply(ui cli.Ui, resp *api.LicenseReply) int {
}
}
func
outputLicenseInfo
(
ui
cli
.
Ui
,
lic
*
api
.
License
,
expired
bool
)
{
func
outputLicenseInfo
(
ui
cli
.
Ui
,
lic
*
api
.
License
,
expired
bool
,
validity
string
)
{
expStr
:=
""
if
expired
{
expStr
=
fmt
.
Sprintf
(
"Expired At
:
%s"
,
lic
.
ExpirationTime
.
String
())
expStr
=
fmt
.
Sprintf
(
"Expired At
|
%s"
,
lic
.
ExpirationTime
.
String
())
}
else
{
expStr
=
fmt
.
Sprintf
(
"Expires At
:
%s"
,
lic
.
ExpirationTime
.
String
())
expStr
=
fmt
.
Sprintf
(
"Expires At
|
%s"
,
lic
.
ExpirationTime
.
String
())
}
output
:=
[]
string
{
fmt
.
Sprintf
(
"License ID: %s"
,
lic
.
LicenseID
),
fmt
.
Sprintf
(
"Customer ID: %s"
,
lic
.
CustomerID
),
fmt
.
Sprintf
(
"License Status|%s"
,
validity
),
fmt
.
Sprintf
(
"License ID|%s"
,
lic
.
LicenseID
),
fmt
.
Sprintf
(
"Customer ID|%s"
,
lic
.
CustomerID
),
expStr
,
fmt
.
Sprintf
(
"License ID
:
%s"
,
lic
.
LicenseID
),
fmt
.
Sprintf
(
"Customer ID
:
%s"
,
lic
.
CustomerID
),
fmt
.
Sprintf
(
"Terminates At
:
%s"
,
lic
.
TerminationTime
.
String
()),
fmt
.
Sprintf
(
"Datacenter
:
%s"
,
lic
.
InstallationID
),
fmt
.
Sprintf
(
"License ID
|
%s"
,
lic
.
LicenseID
),
fmt
.
Sprintf
(
"Customer ID
|
%s"
,
lic
.
CustomerID
),
fmt
.
Sprintf
(
"Terminates At
|
%s"
,
lic
.
TerminationTime
.
String
()),
fmt
.
Sprintf
(
"Datacenter
|
%s"
,
lic
.
InstallationID
),
}
ui
.
Output
(
formatKV
(
output
))
// ui.Output(fmt.Sprintf("License ID: %s", lic.LicenseID))
// ui.Output(fmt.Sprintf("Customer ID: %s", lic.CustomerID))
// ui.Output(fmt.Sprintf("Terminates At: %s", lic.TerminationTime.String()))
// ui.Output(fmt.Sprintf("Datacenter: %s", lic.InstallationID))
if
len
(
lic
.
Modules
)
>
0
{
ui
.
Output
(
"Modules:"
)
for
_
,
mod
:=
range
lic
.
Modules
{
...
...
This diff is collapsed.
Click to expand it.
command/license_get_test.go
+
7
-
4
View file @
5372a522
...
...
@@ -18,10 +18,13 @@ func TestCommand_LicenseGet_OSSErr(t *testing.T) {
ui
:=
new
(
cli
.
MockUi
)
cmd
:=
&
LicenseGetCommand
{
Meta
:
Meta
{
Ui
:
ui
}}
if
code
:=
cmd
.
Run
([]
string
{
"-address="
+
url
});
code
!=
1
{
require
.
Equal
(
t
,
1
,
code
)
}
code
:=
cmd
.
Run
([]
string
{
"-address="
+
url
})
require
.
Equal
(
t
,
1
,
code
)
require
.
Contains
(
t
,
ui
.
ErrorWriter
.
String
(),
"Nomad Enterprise only endpoint"
)
if
srv
.
Enterprise
{
require
.
Contains
(
t
,
ui
.
OutputWriter
.
String
(),
"License Status"
)
}
else
{
require
.
Contains
(
t
,
ui
.
ErrorWriter
.
String
(),
"Nomad Enterprise only endpoint"
)
}
}
This diff is collapsed.
Click to expand it.
command/license_put.go
+
0
-
3
View file @
5372a522
...
...
@@ -35,9 +35,6 @@ Install a new license from stdin:
$ nomad license put -
Install a new license from a string:
$ nomad license put "<license blob>"
`
return
strings
.
TrimSpace
(
helpText
)
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help