Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
boilr
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
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
ifs
boilr
Commits
aa7891d6
Commit
aa7891d6
authored
9 years ago
by
Tamer Tas
Browse files
Options
Downloads
Patches
Plain Diff
Validate templates by doing a test run
parent
aa1ee39f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pkg/cmd/root.go
+1
-1
1 addition, 1 deletion
pkg/cmd/root.go
pkg/cmd/use.go
+4
-2
4 additions, 2 deletions
pkg/cmd/use.go
pkg/cmd/util/validation.go
+24
-0
24 additions, 0 deletions
pkg/cmd/util/validation.go
pkg/cmd/validate.go
+1
-1
1 addition, 1 deletion
pkg/cmd/validate.go
with
30 additions
and
4 deletions
pkg/cmd/root.go
+
1
−
1
View file @
aa7891d6
...
...
@@ -7,8 +7,8 @@ var Root = &cli.Command{
}
func
Run
()
{
// TODO trap c-c to rollback transactions
// TODO use command factories instead of global command variables
Init
.
PersistentFlags
()
.
BoolP
(
"force"
,
"f"
,
false
,
"Recreate directories if they exist"
)
Root
.
AddCommand
(
Init
)
...
...
This diff is collapsed.
Click to expand it.
pkg/cmd/use.go
+
4
−
2
View file @
aa7891d6
...
...
@@ -22,6 +22,8 @@ func TemplateInRegistry(name string) (bool, error) {
return
ok
,
nil
}
// TODO add --use-defaults flag to execute a template without user prompts
// TODO add --use-cache flag to execute a template from previous answers to prompts
var
Use
=
&
cli
.
Command
{
Use
:
"use <template-name> <target-dir>"
,
Short
:
"Executes a project template"
,
...
...
@@ -50,12 +52,12 @@ var Use = &cli.Command{
}
if
err
:=
tmpl
.
Execute
(
targetDir
);
err
!=
nil
{
// Delete if execute transaction fails
// Delete
s the target dir
if execute transaction fails
defer
os
.
RemoveAll
(
targetDir
)
exit
.
Fatal
(
fmt
.
Errorf
(
"use: %s"
,
err
))
}
exit
.
OK
(
"Successfully executed the project template %v
o
n %v"
,
tmplName
,
targetDir
)
exit
.
OK
(
"Successfully executed the project template %v
i
n %v"
,
tmplName
,
targetDir
)
},
}
This diff is collapsed.
Click to expand it.
pkg/cmd/util/validation.go
+
24
−
0
View file @
aa7891d6
...
...
@@ -3,8 +3,11 @@ package util
import
(
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/tmrts/tmplt/pkg/template"
"github.com/tmrts/tmplt/pkg/util/osutil"
"github.com/tmrts/tmplt/pkg/util/validate"
)
...
...
@@ -45,6 +48,23 @@ func ValidateArgs(args []string, validations []validate.Argument) error {
return
nil
}
func
testTemplate
(
path
string
)
error
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
""
,
"tmplt-validation-test"
)
if
err
!=
nil
{
return
err
}
else
{
defer
os
.
RemoveAll
(
tmpDir
)
}
tmpl
,
err
:=
template
.
Get
(
path
)
if
err
!=
nil
{
return
err
}
// TODO add --use-defaults flag to stop asking for user input
return
tmpl
.
Execute
(
tmpDir
)
}
func
ValidateTemplate
(
tmplPath
string
)
(
bool
,
error
)
{
if
exists
,
err
:=
osutil
.
DirExists
(
tmplPath
);
!
exists
{
if
err
!=
nil
{
...
...
@@ -62,5 +82,9 @@ func ValidateTemplate(tmplPath string) (bool, error) {
return
false
,
fmt
.
Errorf
(
"template should contain %q directory"
,
"template"
)
}
if
err
:=
testTemplate
(
tmplPath
);
err
!=
nil
{
return
false
,
err
}
return
true
,
nil
}
This diff is collapsed.
Click to expand it.
pkg/cmd/validate.go
+
1
−
1
View file @
aa7891d6
...
...
@@ -24,6 +24,6 @@ var Validate = &cli.Command{
MustValidateTemplate
(
templatePath
)
exit
.
OK
(
"Template is valid
.
"
)
exit
.
OK
(
"Template is valid"
)
},
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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