Skip to content

A tool for scan and replace file content. Instead of global search and replace, it can specify replace scope

License

Notifications You must be signed in to change notification settings

CWKSC/scan-replace-kotlin-deprecated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScanReplace.kt

A tool for scan and replace file content

Instead of global search and replace, it can specify replace scope

(Currently README.md is wrong, fix later)

Usage

java -jar ScanReplace-<version>.jar [init]

Example:

java -jar ScanReplace-0.1.0.jar
java -jar ScanReplace-0.1.0.jar init

Get Started

Download latest version on Release, type

java -jar ScanReplace-<version>.jar init

Following message will show in screen

file_key.json                  created
key_value.json                 created
scan_replace_config.json       created

Change file_key.json content to

{
    "test.txt": ["key1", "key2"]
}

Change key_value.json content to

{
    "key1": "[It is key1]",
    "key2": "[It is key2]"
}

Create test.txt

key1
key2

Type

java -jar ScanReplace-<version>.jar

Content of test.txt will change to be

[It is key1]
[It is key2]

Document

file_key.json

{
    "filePath": ["key1", "key2"],
    "...": ["..."]
}

filePath

filePath in file_key.json can refer under directory

e.g. dir1/dir2/test.txt

key

Only the key declare in file_key.json to corresponding file will be scan and replace

{
    "test.txt": ["key1", "key2"]
}
{
    "key1": "[It is key1]",
    "key2": "[It is key2]"
}
key1
key2

key2 in test.txt will not be replace, because key2 not declare in file_key.json to corresponding file

You can check out a example in example/key2-not-replace/

key_value.json

{
    "key": "value",
    "...": "..."
}

scan-replace-config.json

{
    "file_key": "file_key.json",
    "key_value": "key_value.json",
    "output": "",
    "file_prefix": "",
    "file_suffix": "",
    "key_prefix": "",
    "key_suffix": ""
}

file_key

Define a path of file_key json, default is file_key.json

key_value

Define a path of key_value json, default is key_value.json

output

Define a path of output folder, default is empty ""

{
    "..." : "...",
    "output": "output/",
    "..." : "..."
}

Leave it blank "" will replace file in-place

You can check out a example in example/output-folder/

file_prefix, file_suffix

It is a global setting of file path with prefix and suffix

A common setting is prefix with some folder, to change the root of reference in file_key.json

file_suffix is uncommon to use but provided

{
    "..." : "...",
    "file_prefix": "directory/",
    "file_suffix": ""
}

All filePath in file_key.json will append prefix and suffix

{
    "filePath1": ["key1", "key2"],
    "filePath2": ["key1", "key2"]
}

equivalent to

{
    "directory/filePath1": ["key1", "key2"],
    "directory/filePath2": ["key1", "key2"]
}

key_prefix key_suffix

It is a global setting of searching key with prefix and suffix

A common setting is prefix with < and suffix with > (or {{ and }} )

{
    "..." : "...",
    "key_prefix": "<",
    "key_suffix": ">"
}

All key in key_value.json will append prefix and suffix

{
    "key1" : "value",
    "key2" : "value"
}

equivalent to

{
    "<key1>" : "value",
    "<key2>" : "value"
}

Build jar

.\gradlew jar

About

A tool for scan and replace file content. Instead of global search and replace, it can specify replace scope

Resources

License

Stars

Watchers

Forks

Packages

No packages published