Skip to content

Commit

Permalink
Rename regolith tool to regolith apply-filter (#234)
Browse files Browse the repository at this point in the history
* Removed the isTool property from the filter.json definition.

* Renamed the 'tool' command to 'apply-filter' in code and the documentation.

* Renamed some of the test files to refer to 'apply-filter' command not the 'tool' command.

* Bring back docs change

Co-authored-by: Piotr Brzozowski <[email protected]>
  • Loading branch information
Nusiq and stirante authored Nov 18, 2022
1 parent d98b96e commit 270156b
Show file tree
Hide file tree
Showing 27 changed files with 35 additions and 47 deletions.
1 change: 0 additions & 1 deletion docs/docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Example config, with many options explained:
// - "arch" - the architecture (e.g. "amd64", "arm64")
// - "version" - the version of regolith or 0.0.0 when running from source
// - "debug" - whether the debug flag is passed to regolith or not
// - "isTool" - whether the filter is run from a tool subcommand or not
// - "profile" - current profile being run
// - "filterLocation" - absolute location of the filter folder
"when": "os == 'windows' && arch == 'amd64'"
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/guide/filter-run-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Filter Run Modes
There are 3 ways of running Regolith:
- `regolith run`
- `regolith watch`
- `regolith tool`
- `regolith apply-filter`

## Run and Watch Commands

Expand Down Expand Up @@ -39,18 +39,18 @@ because after a successful run Regolith moves the files of the copy to the
the original data folder (this is useful for the filters so that they can store
some data between runs).

## Tool Command - Running Regolith Destructively
## Apply-Filter Command - Running Regolith Destructively

Running Regolith with `regolith run` or `regolith watch` is a safe operation because the filters can
only modify the data folder but not RP and BP. Sometimes you want to modify the RP and BP directly
in a destructive way. This is where the tool-filters come in handy. You can use any filter as a tool
by running the `regolith tool` command. Unlike the `regolith run` command, the `regolith tool`
in a destructive way. This is where the apply-filter command come in handy. You can apply any filter
by running the `regolith apply-filter` command. Unlike the `regolith run` command, the `regolith apply-filter`
command runs only one filter instead of running entire profile.

The command is used like this:

```
regolith tool <filter-name> [args...]
regolith apply-filter <filter-name> [args...]
```

The `filter-name` is the name of one of the filters installed in your project. The `args` is a list of arguments passed to the filter.
28 changes: 14 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ every time a change in files of the project's RP, BP, or data folders is detecte
uses the same syntax as "regolith run". You can use "regolith help run" to learn more about the
command.
`
const regolithToolDesc = `
This command runs single selected filter as a tool for modifying project source files. Running this
is a destructive operation that modifies RP, BP and data folders, so it is recommended to be cautious
when using this command and to have a way to revert the changes (e.g. using Git).
const regolithApplyFilter = `
This command runs single selected filter and applies its changes to the project source files. Running
this is a destructive operation that modifies RP, BP and data folders, so it is recommended to be
cautious when using this command and to have a way to revert the changes (e.g. using Git).
Every filter can be used as a tool as long as it's defined in the "config.json" file in the
Every filter can be used this way as long as it's defined in the "config.json" file in the
"filterDefinitions" section.
The "regolith tool" command runs on a copy of the project's files and copies them back to the
project only if the filter was successful. This means that if the filter fails, the project's files
will not be modified.
The "regolith apply-filter" command runs on a copy of the project's files and copies them back to the
project only if the filter is successful. This means that if the filter fails, the project's files
aren't modified.
`
const regolithInstallDesc = `
Downloads and installs Regolith filters from the internet, and adds them to the "filterDefinitions"
Expand Down Expand Up @@ -266,22 +266,22 @@ func main() {
},
}
subcomands = append(subcomands, cmdWatch)
// regolith tool
cmdTool := &cobra.Command{
Use: "tool <filter_name> [filter_args...]",
// regolith apply-filter
cmdApplyFilter := &cobra.Command{
Use: "apply-filter <filter_name> [filter_args...]",
Short: "Runs selected filter to destructively modify the project files",
Long: regolithToolDesc,
Long: regolithApplyFilter,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
return
}
filter := args[0]
filterArgs := args[1:] // First arg is the filter name
err = regolith.Tool(filter, filterArgs, burrito.Debug)
err = regolith.ApplyFilter(filter, filterArgs, burrito.Debug)
},
}
subcomands = append(subcomands, cmdTool)
subcomands = append(subcomands, cmdApplyFilter)
// regolith clean
var userCache bool
cmdClean := &cobra.Command{
Expand Down
1 change: 0 additions & 1 deletion regolith/condition_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ func prepareScope(ctx RunContext) map[string]interface{} {
"version": semverString,
"profile": ctx.Profile,
"filterLocation": ctx.AbsoluteLocation,
"isTool": ctx.IsTool,
}
}
2 changes: 1 addition & 1 deletion regolith/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func ExportProject(
}

// InplaceExportProject copies the files from the tmp paths (tmp/BP, tmp/RP and
// tmp/data) into the project's source files. It's used by the "regolith tool"
// tmp/data) into the project's source files. It's used by the "regolith apply-filter"
// command. This operation is destructive and cannot be undone.
func InplaceExportProject(
config *Config, dotRegolithPath string,
Expand Down
3 changes: 1 addition & 2 deletions regolith/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type RunContext struct {
Profile string
Parent *RunContext
DotRegolithPath string
IsTool bool

// interruptionChannel is a channel that is used to notify about changes
// in the sourec files, in order to trigger a restart of the program in
Expand Down Expand Up @@ -130,7 +129,7 @@ func filterFromObject(obj map[string]interface{}) (*Filter, error) {
if ok {
// Try to parse arguments as []interface{} and as []string
// one format is used when parsed from JSON, and the other format is
// used by the Tool() function.
// used by the ApplyFilter() function.
switch arguments := arguments.(type) {
case []interface{}:
s := make([]string, len(arguments))
Expand Down
1 change: 0 additions & 1 deletion regolith/filter_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func (f *ProfileFilter) Run(context RunContext) (bool, error) {
Parent: &context,
interruptionChannel: context.interruptionChannel,
DotRegolithPath: context.DotRegolithPath,
IsTool: context.IsTool,
})
}

Expand Down
1 change: 0 additions & 1 deletion regolith/filter_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func (f *RemoteFilter) run(context RunContext) error {
Profile: context.Profile,
Parent: context.Parent,
DotRegolithPath: context.DotRegolithPath,
IsTool: context.IsTool,
}
// Disabled filters are skipped
disabled, err := filter.IsDisabled(runContext)
Expand Down
10 changes: 4 additions & 6 deletions regolith/main_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ func runOrWatch(profileName string, debug, watch bool) error {
Parent: nil,
Profile: profileName,
DotRegolithPath: dotRegolithPath,
IsTool: false,
}
if watch { // Loop until program termination (CTRL+C)
context.StartWatchingSourceFiles()
Expand Down Expand Up @@ -263,10 +262,10 @@ func Watch(profileName string, debug bool) error {
return runOrWatch(profileName, debug, true)
}

// Tool handles the "regolith tool" command. It runs a filter in a "tool mode".
// Tool mode modifies RP and BP file in place (using source). The config and
// properties of the tool filter are passed via commandline.
func Tool(filterName string, filterArgs []string, debug bool) error {
// ApplyFilter handles the "regolith apply-filter" command.
// ApplyFilter mode modifies RP and BP file in place (using source). The config and
// properties of the filter are passed via commandline.
func ApplyFilter(filterName string, filterArgs []string, debug bool) error {
InitLogging(debug)
// Load the Config and the profile
configJson, err := LoadConfigAsMap()
Expand Down Expand Up @@ -323,7 +322,6 @@ func Tool(filterName string, filterArgs []string, debug bool) error {
DotRegolithPath: dotRegolithPath,
interruptionChannel: nil,
AbsoluteLocation: path,
IsTool: true,
}
// Check the filter
err = filterRunner.Check(runContext)
Expand Down
5 changes: 0 additions & 5 deletions regolith/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,11 @@ func CheckProfileImpl(
) error {
// Check whether every filter, uses a supported filter type
for _, f := range profile.Filters {
isTool := false
if parentContext != nil {
isTool = parentContext.IsTool
}
err := f.Check(RunContext{
Config: &config,
Parent: parentContext,
Profile: profileName,
DotRegolithPath: dotRegolithPath,
IsTool: isTool,
})
if err != nil {
return burrito.WrapErrorf(err, filterRunnerCheckError, f.GetId())
Expand Down
12 changes: 6 additions & 6 deletions test/tool_filter_test.go → test/apply_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/otiai10/copy"
)

// TestToolFilter tests the 'regolith tool' command
func TestToolFilter(t *testing.T) {
// TestApplyFilter tests the 'regolith apply-filter' command
func TestApplyFilter(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatal("Unable to get current working directory")
Expand All @@ -27,13 +27,13 @@ func TestToolFilter(t *testing.T) {
defer os.RemoveAll(tmpDir)
defer os.Chdir(wd)
// Copy the test project to the working directory
project, err := filepath.Abs(filepath.Join(toolFilterPath, "project"))
project, err := filepath.Abs(filepath.Join(applyFilterPath, "project"))
if err != nil {
t.Fatal(
"Unable to get absolute path to the test project:", err)
}
expectedResult, err := filepath.Abs(
filepath.Join(toolFilterPath, "tool_filtered_project"))
filepath.Join(applyFilterPath, "filtered_project"))
if err != nil {
t.Fatal(
"Unable to get absolute path to the expected build result:", err)
Expand All @@ -51,8 +51,8 @@ func TestToolFilter(t *testing.T) {
}
// THE TEST
os.Chdir(tmpDir)
if err := regolith.Tool("test_filter", []string{"Regolith"}, true); err != nil {
t.Fatal("'regolith tool' failed:", err.Error())
if err := regolith.ApplyFilter("test_filter", []string{"Regolith"}, true); err != nil {
t.Fatal("'regolith apply-filter' failed:", err.Error())
}
// Load expected result
expectedPaths, err := listPaths(expectedResult, expectedResult)
Expand Down
8 changes: 4 additions & 4 deletions test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ const (
// filter.
regolithUpdatePath = "testdata/regolith_update"

// toolFilterPath is a directory that contains the files for testing
// 'regolith tool' command. It contains two projects, one before running
// 'regolith tool' command and one after. The command should run the
// applyFilterPath is a directory that contains the files for testing
// 'regolith apply-filter' command. It contains two projects, one before running
// 'regolith apply-filter' command and one after. The command should run the
// 'test_filter' with 'Regolith' argument. The filter adds a single file
// with 'Hello Regolith!' greeting.
toolFilterPath = "testdata/tool_filter"
applyFilterPath = "testdata/apply_filter"

// conditionalFilterPath contains two subdirectories 'project' and
// 'expected_build_result'. The project is a Regolith project with a simple
Expand Down

0 comments on commit 270156b

Please sign in to comment.