grim/convey
Clone
Summary
Browse
Changes
Graph
Typo fix
2018-01-14, Gary Kramlich
4022dd81834e
Typo fix
// Convey
// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package
intrinsic
import
(
"fmt"
"github.com/aphistic/gomol"
"github.com/mohae/deepcopy"
"bitbucket.org/rw_grim/convey/state"
"bitbucket.org/rw_grim/convey/tasks"
"bitbucket.org/rw_grim/convey/yaml"
)
// Extend represents a task that extends another task.
type
Extend
struct
{
Task
string
`yaml:"task"`
Environment
yaml
.
StringOrSlice
`yaml:"environment"`
Expand
yaml
.
StringOrSlice
`yaml:"expand"`
ExpandDelimiter
string
`yaml:"expand_delimiter"`
// A copy of the extended task. Must be public so that deepcopy
// can serialize it properly in case an extended task is extended
// itself (when private the innerTask is nil and causes a bad
// data access exception).
InnerTask
tasks
.
Task
}
// Execute runs an extended task.
func
(
e
*
Extend
)
Execute
(
name
string
,
logger
*
gomol
.
LogAdapter
,
env
[]
string
,
st
*
state
.
State
)
error
{
// While extending, certain environment variables can be expanded into
// lists. We store this meta information as a stack on the state, which
// is passed into the inner task execute method (and so on).
return
e
.
InnerTask
.
Execute
(
name
,
logger
,
env
,
st
.
WrapWithExpandableEnv
(
e
.
Environment
,
e
.
Expand
,
e
.
ExpandDelimiter
,
))
}
// New creates a new extend task.
func
(
e
*
Extend
)
New
()
tasks
.
Task
{
return
&
Extend
{}
}
// Valid validates the task.
func
(
e
*
Extend
)
Valid
()
error
{
if
e
.
ExpandDelimiter
==
""
{
e
.
ExpandDelimiter
=
";"
}
return
nil
}
// Dependencies returns a list of tasks that this task depends on.
func
(
e
*
Extend
)
Dependencies
()
[]
string
{
return
[]
string
{
e
.
Task
}
}
// Resolve returns the fully extended task.
func
(
e
*
Extend
)
Resolve
(
taskMap
map
[
string
]
tasks
.
Task
)
error
{
task
,
ok
:=
taskMap
[
e
.
Task
]
if
!
ok
{
// Should never happen due to dependency order
return
fmt
.
Errorf
(
"Extending undeclared task '%s'"
,
e
.
Task
)
}
// Some tasks may set their own fields, e.g. when mapping things
// to the correct runtime environment. In order to make sure that
// the inner task doesn't cache something from another run, we
// do a clone of the task here so we get our own copy to muck with.
e
.
InnerTask
=
deepcopy
.
Copy
(
task
).(
tasks
.
Task
)
return
nil
}