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
f6919cf1
Commit
f6919cf1
authored
Mar 24, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Short-circuit -h and --help to printing help for the top-level cmd
parent
4d10489f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
1 deletion
+18
-1
packer/environment.go
packer/environment.go
+8
-1
packer/environment_test.go
packer/environment_test.go
+10
-0
No files found.
packer/environment.go
View file @
f6919cf1
...
@@ -14,6 +14,13 @@ import (
...
@@ -14,6 +14,13 @@ import (
//
//
// The mapping of command names to command interfaces is in the
// The mapping of command names to command interfaces is in the
// Environment struct.
// Environment struct.
//
// Run should run the actual command with the given environmet and
// command-line arguments. It should return the exit status when it is
// finished.
//
// Synopsis should return a one-line, short synopsis of the command.
// This should be less than 50 characters ideally.
type
Command
interface
{
type
Command
interface
{
Run
(
env
*
Environment
,
args
[]
string
)
int
Run
(
env
*
Environment
,
args
[]
string
)
int
Synopsis
()
string
Synopsis
()
string
...
@@ -43,7 +50,7 @@ func NewEnvironment() *Environment {
...
@@ -43,7 +50,7 @@ func NewEnvironment() *Environment {
// Executes a command as if it was typed on the command-line interface.
// Executes a command as if it was typed on the command-line interface.
// The return value is the exit code of the command.
// The return value is the exit code of the command.
func
(
e
*
Environment
)
Cli
(
args
[]
string
)
int
{
func
(
e
*
Environment
)
Cli
(
args
[]
string
)
int
{
if
len
(
args
)
==
0
{
if
len
(
args
)
==
0
||
args
[
0
]
==
"--help"
||
args
[
0
]
==
"-h"
{
e
.
PrintHelp
()
e
.
PrintHelp
()
return
1
return
1
}
}
...
...
packer/environment_test.go
View file @
f6919cf1
...
@@ -14,6 +14,16 @@ func TestEnvironment_DefaultCli_Empty(t *testing.T) {
...
@@ -14,6 +14,16 @@ func TestEnvironment_DefaultCli_Empty(t *testing.T) {
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{}),
1
,
"CLI with no args"
)
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{}),
1
,
"CLI with no args"
)
}
}
func
TestEnvironment_DefaultCli_Help
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
defaultEnv
:=
NewEnvironment
()
// Test the basic version options
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"--help"
}),
1
,
"--help should print"
)
assert
.
Equal
(
defaultEnv
.
Cli
([]
string
{
"-h"
}),
1
,
"--help should print"
)
}
func
TestEnvironment_DefaultCli_Version
(
t
*
testing
.
T
)
{
func
TestEnvironment_DefaultCli_Version
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
...
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