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
c155296d
Commit
c155296d
authored
7 years ago
by
Tom Wilkie
Browse files
Options
Downloads
Patches
Plain Diff
Exit with 0 for no differences found, 1 for difference found, 2 for other error.
parent
56ef55da
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/diff.go
+7
-5
7 additions, 5 deletions
cmd/diff.go
main.go
+9
-1
9 additions, 1 deletion
main.go
with
16 additions
and
6 deletions
cmd/diff.go
+
7
−
5
View file @
c155296d
...
...
@@ -33,6 +33,8 @@ import (
const
flagDiffStrategy
=
"diff-strategy"
var
ErrDiffFound
=
fmt
.
Errorf
(
"Differences found."
)
func
init
()
{
diffCmd
.
PersistentFlags
()
.
String
(
flagDiffStrategy
,
"all"
,
"Diff strategy, all or subset."
)
RootCmd
.
AddCommand
(
diffCmd
)
...
...
@@ -67,7 +69,7 @@ var diffCmd = &cobra.Command{
sort
.
Sort
(
utils
.
AlphabeticalOrder
(
objs
))
diff
erences
Found
:=
false
diffFound
:=
false
for
_
,
obj
:=
range
objs
{
desc
:=
fmt
.
Sprintf
(
"%s/%s"
,
obj
.
GetKind
(),
fqName
(
obj
))
log
.
Debugf
(
"Fetching "
,
desc
)
...
...
@@ -89,7 +91,7 @@ var diffCmd = &cobra.Command{
fmt
.
Fprintf
(
out
,
"- live %s
\n
+ config %s
\n
"
,
desc
,
desc
)
if
liveObj
==
nil
{
fmt
.
Fprintf
(
out
,
"%s doesn't exist on server
\n
"
,
desc
)
diff
erences
Found
=
true
diffFound
=
true
continue
}
...
...
@@ -100,7 +102,7 @@ var diffCmd = &cobra.Command{
diff
:=
gojsondiff
.
New
()
.
CompareObjects
(
liveObjObject
,
obj
.
Object
)
if
diff
.
Modified
()
{
diff
erences
Found
=
true
diffFound
=
true
fcfg
:=
formatter
.
AsciiFormatterConfig
{
Coloring
:
istty
(
out
),
}
...
...
@@ -115,8 +117,8 @@ var diffCmd = &cobra.Command{
}
}
if
diff
erences
Found
{
return
fmt
.
Errorf
(
"Differences f
ound
."
)
if
diffFound
{
return
ErrDiffF
ound
}
return
nil
},
...
...
This diff is collapsed.
Click to expand it.
main.go
+
9
−
1
View file @
c155296d
...
...
@@ -16,6 +16,8 @@
package
main
import
(
"os"
log
"github.com/sirupsen/logrus"
"github.com/ksonnet/kubecfg/cmd"
...
...
@@ -32,7 +34,13 @@ func main() {
// errors, like invalid command line flags.
logFmt
:=
cmd
.
NewLogFormatter
(
log
.
StandardLogger
()
.
Out
)
log
.
SetFormatter
(
logFmt
)
log
.
Error
(
err
.
Error
())
log
.
Fatal
(
err
.
Error
())
switch
err
{
case
cmd
.
ErrDiffFound
:
os
.
Exit
(
1
)
default
:
os
.
Exit
(
2
)
}
}
}
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