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
4a510378
Commit
4a510378
authored
7 years ago
by
Ted Hahn
Browse files
Options
Downloads
Patches
Plain Diff
Add a flag for extvars
parent
69c59d9f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/root.go
+17
-1
17 additions, 1 deletion
cmd/root.go
with
17 additions
and
1 deletion
cmd/root.go
+
17
−
1
View file @
4a510378
...
...
@@ -3,10 +3,12 @@ package cmd
import
(
"bytes"
"encoding/json"
"errors"
goflag
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/golang/glog"
"github.com/spf13/cobra"
...
...
@@ -21,13 +23,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 +80,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
,
errors
.
New
(
"Failed to parse extvar: missing '=' in "
+
extvar
)
}
vm
.
ExtVar
(
kv
[
0
],
kv
[
1
])
}
return
vm
,
nil
}
...
...
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