Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
ksonnet
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ijaz Ahmad
ksonnet
Commits
c4e5813a
Commit
c4e5813a
authored
7 years ago
by
Angus Lees
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #28 from GauntletWizard/extvar
Add a flag for extvars
parents
08eabe68
518c888d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/root.go
+16
-1
16 additions, 1 deletion
cmd/root.go
cmd/show_test.go
+2
-0
2 additions, 0 deletions
cmd/show_test.go
testdata/test.jsonnet
+2
-0
2 additions, 0 deletions
testdata/test.jsonnet
with
20 additions
and
1 deletion
cmd/root.go
+
16
−
1
View file @
c4e5813a
...
...
@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/golang/glog"
"github.com/spf13/cobra"
...
...
@@ -21,13 +22,15 @@ import (
)
const
(
flagJpath
=
"jpath"
flagJpath
=
"jpath"
flagExtVar
=
"extVar"
)
var
clientConfig
clientcmd
.
ClientConfig
func
init
()
{
RootCmd
.
PersistentFlags
()
.
StringP
(
flagJpath
,
"J"
,
""
,
"Additional jsonnet library search path"
)
RootCmd
.
PersistentFlags
()
.
StringSliceP
(
flagExtVar
,
"V"
,
nil
,
"Values of external variables"
)
// The "usual" clientcmd/kubectl flags
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
...
...
@@ -76,6 +79,18 @@ func JsonnetVM(cmd *cobra.Command) (*jsonnet.VM, error) {
vm
.
JpathAdd
(
p
)
}
extvars
,
err
:=
flags
.
GetStringSlice
(
flagExtVar
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
extvar
:=
range
extvars
{
kv
:=
strings
.
SplitN
(
extvar
,
"="
,
2
)
if
len
(
kv
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"Failed to parse extvar: missing '=' in %s"
,
extvar
)
}
vm
.
ExtVar
(
kv
[
0
],
kv
[
1
])
}
return
vm
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
cmd/show_test.go
+
2
−
0
View file @
c4e5813a
...
...
@@ -45,6 +45,7 @@ func TestShow(t *testing.T) {
"bool": true,
"number": 42,
"string": "bar",
"notAVal": "aVal",
"array": ["one", 2, [3]],
"object": {"foo": "bar"}
}
...
...
@@ -60,6 +61,7 @@ func TestShow(t *testing.T) {
"-J"
,
filepath
.
FromSlash
(
"../testdata/lib"
),
"-o"
,
format
,
filepath
.
FromSlash
(
"../testdata/test.jsonnet"
),
"-V"
,
"aVar=aVal"
,
})
t
.
Log
(
"output is"
,
output
)
...
...
This diff is collapsed.
Click to expand it.
testdata/test.jsonnet
+
2
−
0
View file @
c4e5813a
local
test
=
import
"test.libsonnet"
;
local
aVar
=
std
.
extVar
(
"aVar"
);
{
apiVersion
:
"v1"
,
...
...
@@ -6,6 +7,7 @@ local test = import "test.libsonnet";
items
:
[
test
{
string
:
"bar"
,
notAVal
:
aVar
,
}
],
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment