Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
46f5a9b1
Commit
46f5a9b1
authored
Aug 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parse --machine-readable and set it
parent
aa143a33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
1 deletion
+62
-1
packer.go
packer.go
+28
-1
packer_test.go
packer_test.go
+34
-0
No files found.
packer.go
View file @
46f5a9b1
...
...
@@ -76,8 +76,13 @@ func main() {
log
.
Printf
(
"Setting cache directory: %s"
,
cacheDir
)
cache
:=
&
packer
.
FileCache
{
CacheDir
:
cacheDir
}
// Determine if we're in machine-readable mode by mucking around with
// the arguments...
args
,
machineReadable
:=
extractMachineReadable
(
os
.
Args
[
1
:
])
defer
plugin
.
CleanupClients
()
// Create the environment configuration
envConfig
:=
packer
.
DefaultEnvironmentConfig
()
envConfig
.
Cache
=
cache
envConfig
.
Commands
=
config
.
CommandNames
()
...
...
@@ -86,6 +91,11 @@ func main() {
envConfig
.
Components
.
Hook
=
config
.
LoadHook
envConfig
.
Components
.
PostProcessor
=
config
.
LoadPostProcessor
envConfig
.
Components
.
Provisioner
=
config
.
LoadProvisioner
if
machineReadable
{
envConfig
.
Ui
=
&
packer
.
MachineReadableUi
{
Writer
:
os
.
Stdout
,
}
}
env
,
err
:=
packer
.
NewEnvironment
(
envConfig
)
if
err
!=
nil
{
...
...
@@ -96,7 +106,7 @@ func main() {
setupSignalHandlers
(
env
)
exitCode
,
err
:=
env
.
Cli
(
os
.
Args
[
1
:
]
)
exitCode
,
err
:=
env
.
Cli
(
args
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"Error executing CLI: %s
\n
"
,
err
.
Error
())
plugin
.
CleanupClients
()
...
...
@@ -107,6 +117,23 @@ func main() {
os
.
Exit
(
exitCode
)
}
// extractMachineReadable checks the args for the machine readable
// flag and returns whether or not it is on. It modifies the args
// to remove this flag.
func
extractMachineReadable
(
args
[]
string
)
([]
string
,
bool
)
{
for
i
,
arg
:=
range
args
{
if
arg
==
"--machine-readable"
{
// We found it. Slice it out.
result
:=
make
([]
string
,
len
(
args
)
-
1
)
copy
(
result
,
args
[
:
i
])
copy
(
result
[
i
:
],
args
[
i
+
1
:
])
return
result
,
true
}
}
return
args
,
false
}
func
loadConfig
()
(
*
config
,
error
)
{
var
config
config
if
err
:=
decodeConfig
(
bytes
.
NewBufferString
(
defaultConfig
),
&
config
);
err
!=
nil
{
...
...
packer_test.go
View file @
46f5a9b1
package
main
import
(
"reflect"
"testing"
)
func
TestExtractMachineReadable
(
t
*
testing
.
T
)
{
var
args
,
expected
,
result
[]
string
var
mr
bool
// Not
args
=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
result
,
mr
=
extractMachineReadable
(
args
)
expected
=
[]
string
{
"foo"
,
"bar"
,
"baz"
}
if
!
reflect
.
DeepEqual
(
result
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
result
)
}
if
mr
{
t
.
Fatal
(
"should not be mr"
)
}
// Yes
args
=
[]
string
{
"foo"
,
"--machine-readable"
,
"baz"
}
result
,
mr
=
extractMachineReadable
(
args
)
expected
=
[]
string
{
"foo"
,
"baz"
}
if
!
reflect
.
DeepEqual
(
result
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
result
)
}
if
!
mr
{
t
.
Fatal
(
"should be mr"
)
}
}
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