Skip to content

Commit

Permalink
prep 1.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
robrbecker committed Oct 14, 2021
1 parent 182274e commit 8439770
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [1.0.0] - 2021-10-13
### Added
- Initial Version

[1.0.0]: https://github.com/robrbecker/replace/releases/tag/1.0.0
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# replace
Easy to use cross-platform regex replace command line util

### Installing
`pub global activate replace`

or more advanced install
- clone the project
- `pub get`
- `dart compile exe bin/replace.dart -o replace`
- Place the `replace` executable in your path

### Running
`replace <regexp> <replacement> <glob>`

Regexes and globs are Dart style
Glob Syntax: https://pub.dev/packages/glob#syntax

The replacement may contain references to the capture groups in regexp using a backslash followed by the group number. Backslashes not followed by a number return the character immediately following them.

Examples:

Simple strings and filename
`replace word newword filename`

Regex and glob (w/ quotes around arguments)
`replace "(war).*(worlds)" "\1 of the monkeys" **`

### Developing
This project uses cider to maintain the changelog.

`cider log <type> <description>`
type is one of: added, changed, deprecated, removed, fixed, security

Examples:
```
cider log changed 'New turbo V6 engine installed'
cider log added 'Support for rocket fuel and kerosene'
cider log fixed 'Wheels falling off sporadically'
```

When ready to release just run

`cider bump <part>` (part is major, minor, patch)
and
`cider release`
29 changes: 29 additions & 0 deletions bin/replace.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:io';
import 'package:cli_script/cli_script.dart';
import 'package:file/local.dart';
import 'package:glob/glob.dart';

void main(List<String> args) async {
var usage = 'replace <regexp> <replacement> <glob>';
if (args.length < 3) {
print(usage);
return;
}
var regexp = args[0];
var replacement = args[1];
var glob = Glob(args[2]);

var files = await glob
.listFileSystem(const LocalFileSystem()).toList();
var transformer = replace(regexp, replacement, all: true, caseSensitive: false);

for (var f in files) {
print(f.path);
var contents = (await asStream(f).transform<String>(transformer).toList()).first;
File(f.path).writeAsStringSync(contents);
}
}

Stream<String> asStream(FileSystemEntity f) async* {
yield await File(f.path).readAsString();
}
21 changes: 21 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: replace
version: 1.0.0
description: An easy to use cross-platform regex replace command line util.
repository: https://github.com/robrbecker/replace

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
args: ^2.0.0
cli_script: ^0.2.3
file: ^6.0.0
glob: ^2.0.0

executables:
replace:

cider:
link_template:
tag: https://github.com/robrbecker/replace/releases/tag/%tag%
diff: https://github.com/robrbecker/replace/compare/%from%...%to%

0 comments on commit 8439770

Please sign in to comment.