Skip to content

Commit

Permalink
Bumped version number to v0.5.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
mipmip committed Mar 7, 2023
1 parent 74ead55 commit 8cb62dd
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 61 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# CHANGELOG

## Fred 0.5.0 - di 7 maart 2023

- BREAKING: renamed and reordered multiple commands
- feature: unset_key
- feature: toggle_bool_val
- feature: set_bool_val, set_string_val

## Fred 0.4.0 - vr 17 feb 2023
- rename taxo to front-matter everywhere
- feature: set_key_val
Expand Down
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ Fred is a cli utility for precisely editing YAML-nodes inside the front matter
of a markdown file.

## Features

- Unset key
- Rename the key of a scalar node
- Replace value of scalar node
- Replace string value of scalar node
- Toggle bool value of scalar node
- Scaler node at 1st level are automatically defined as variable
- Substitute variables inside scalar node when it's defined lines earlier
- Recursive mode for processing files inside directories
- Dry run mode

## Installation

Expand All @@ -28,23 +33,24 @@ of a markdown file.
## Usage

```bash
Usage:

fred help

Options:

--help Show this help.
-d, --dryrun Dry run. Output only [type:Bool]
-r, --recursive Path is a directory. All .md files in the directory will be processed [type:Bool]
-v, --verbose Be verbose [type:Bool]

Sub Commands:

echo echo display one node by key
set_bool_val Set boolean value for front matter key
set_string_val Set string value for front matter key
unset_key Remove key from front matter
replace_key Find and replace key in front matter
replace_string_val Find and replace a string value in front matter
toggle_bool_val Toggle a bool value in front matter, if true set false, if false or missing set true
replace_1st_level_vars replace variables found on 1st level in other levels in inside front matter
replace_includes replace includes inside front matter
process_functions replace $FORMAT and $INCLUDE inside front matter
version version
replace_1st_level_vars replace 1st level variables in inside the front matter
rename_taxo_key rename a taxo string val
rename_taxo_val rename a taxo string val in a single file
```
## Variable usage
Expand Down Expand Up @@ -109,7 +115,6 @@ make run_coverage
make build
```

## Contributing
1. Fork it (<https://github.com/your-github-user/fred/fork>)
Expand Down
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: fred
version: 0.4.0
version: 0.5.0

authors:
- Pim Snel <pim@lingewoud.nl>
- Pim Snel <post@pimsnel.com>

targets:
fred:
Expand Down
5 changes: 3 additions & 2 deletions spec/testfiles/markdown_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
key1: val_old
key2: üòmlaubt
key3:
- hallo
- goodby
- hallo
- goodby
test: true
---

This is some text.
182 changes: 137 additions & 45 deletions src/fred.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ module Fred
puts opts.help_string
end

sub "version" do
desc "version"
usage "fred version"
run do |opts, args|
puts Fred::VERSION
end
end

sub "echo" do
desc "echo display one node by key"
Expand All @@ -42,8 +35,9 @@ module Fred
end
end

sub "process_frontmatter_specials" do
desc "replace $FORMAT and $INCLUDE inside the front matter"

sub "set_bool_val" do
desc "Set boolean value for front matter key"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
Expand All @@ -54,16 +48,28 @@ module Fred
type: String,
required: true

usage "fred process_frontmatter_specials [PATH]"
argument "front_matter_key",
desc: "key to set",
type: String,
required: true

argument "front_matter_val",
desc: "true or false",
type: Bool,
required: true

usage "fred set_bool_val [PATH] [FRONT_MATTER_KEY] [true / false] [options]"

run do |opts, args|
path = args.path

fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.process_all_specials
fs_processor.set_key_val(args.front_matter_key, args.front_matter_val)
end
end

sub "set_key_val" do
desc "Set key and value in the root Front Matter"
sub "set_string_val" do
desc "Set string value for front matter key"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
Expand All @@ -73,16 +79,18 @@ module Fred
desc: "directory or file",
type: String,
required: true

argument "front_matter_key",
desc: "key to set",
type: String,
required: true

argument "front_matter_val",
desc: "value for the key",
desc: "string value to set",
type: String,
required: true

usage "fred set_key_val [PATH] [FRONT_MATTER_KEY] [FRONT_MATTER_VAL]"
usage "fred set_string_val [PATH] [KEY] [VAL] [options]"

run do |opts, args|
path = args.path
Expand All @@ -91,8 +99,8 @@ module Fred
end
end

sub "replace_1st_level_vars" do
desc "replace 1st level variables in inside the front matter"
sub "unset_key" do
desc "Remove key from front matter"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
Expand All @@ -103,17 +111,22 @@ module Fred
type: String,
required: true

usage "fred replace_1st_level_vars [PATH]"
argument "unset_key",
desc: "key to remove",
type: String,
required: true

usage "fred unset_key [PATH] [KEY] [options]"

run do |opts, args|
path = args.path
fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.replace_1st_level_vars
fs_processor.unset_front_matter_key(args.unset_key)
end
end

sub "replace_includes" do
desc "replace includes inside the front matter"
sub "replace_key" do
desc "Find and replace key in front matter"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
Expand All @@ -124,74 +137,153 @@ module Fred
type: String,
required: true

usage "fred replace_includes [PATH] [options]"
argument "key_old",
desc: "key to replace",
type: String,
required: true

argument "key_new",
desc: "new key",
type: String,
required: true

usage "fred replace_key [PATH] [KEY_OLD] [KEY_NEW] [options]"

run do |opts, args|
path = args.path
fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.replace_includes
fs_processor.rename_front_matter_key(args.key_old, args.key_new)
end
end

sub "rename_front_matter_key" do
desc "Rename a Front Matter key"
sub "replace_string_val" do
desc "Find and replace a string value in front matter"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
option "-v", "--verbose", type: Bool, desc: "Be verbose"

argument "front_matter_key_old",
desc: "key to replace",
argument "path",
desc: "directory or file",
type: String,
required: true
argument "front_matter_key_new",
desc: "new key",

argument "front_matter_key",
desc: "key to replace value for",
type: String,
required: true
argument "path",
desc: "directory or file",
argument "front_matter_val_old",
desc: "old value",
type: String,
required: true
argument "front_matter_val_new",
desc: "new value",
type: String,
required: true

usage "fred rename_front_matter_key [front_matter_key_old] [front_matter_key_new] [PATH]"
usage "fred replace_string_val [PATH] [KEY] [VAL_OLD] [VAL_NEW] [options]"

run do |opts, args|
path = args.path
fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.rename_front_matter_key(args.front_matter_key_old, args.front_matter_key_new)
fs_processor = FSProcessor.new(args.path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.rename_front_matter_val(args.front_matter_key, args.front_matter_val_old, args.front_matter_val_new)
end
end

sub "rename_front_matter_val" do
desc "Rename a Front Matter string value in a single file"
sub "toggle_bool_val" do
desc "Toggle a bool value in front matter, if true set false, if false or missing set true"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
option "-v", "--verbose", type: Bool, desc: "Be verbose"

argument "path",
desc: "directory or file",
type: String,
required: true

argument "front_matter_key",
desc: "key to replace value for",
desc: "key to toggle value for",
type: String,
required: true
argument "front_matter_val_old",
desc: "old value",

usage "fred toggle_bool_val [PATH] [KEY] [options]"

run do |opts, args|
fs_processor = FSProcessor.new(args.path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.toggle_bool_val(args.front_matter_key)
end
end

sub "replace_1st_level_vars" do
desc "replace variables found on 1st level in other levels in inside front matter"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
option "-v", "--verbose", type: Bool, desc: "Be verbose"

argument "path",
desc: "directory or file",
type: String,
required: true
argument "front_matter_val_new",
desc: "new value",

usage "fred replace_1st_level_vars [PATH] [options]"

run do |opts, args|
path = args.path
fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.replace_1st_level_vars
end
end

sub "replace_includes" do
desc "replace includes inside front matter"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
option "-v", "--verbose", type: Bool, desc: "Be verbose"

argument "path",
desc: "directory or file",
type: String,
required: true

usage "fred replace_includes [PATH] [options]"
run do |opts, args|
path = args.path
fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.replace_includes
end
end

sub "process_functions" do
desc "replace $FORMAT and $INCLUDE inside front matter"

option "-d", "--dryrun", type: Bool, desc: "Dry run. Output only"
option "-r", "--recursive", type: Bool, desc: "Path is a directory. All .md files in the directory will be processed"
option "-v", "--verbose", type: Bool, desc: "Be verbose"

argument "path",
desc: "directory or file",
type: String,
required: true

usage "fred rename_front_matter_val [front_matter_key] [front_matter_val_old] [front_matter_val_new] [PATH]"
usage "fred process_functions [PATH] [options]"
run do |opts, args|
path = args.path
fs_processor = FSProcessor.new(path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.process_all_specials
end
end


sub "version" do
desc "version"
usage "fred version"
run do |opts, args|
fs_processor = FSProcessor.new(args.path, opts.dryrun, opts.recursive, opts.verbose)
fs_processor.rename_front_matter_val(args.front_matter_key, args.front_matter_val_old, args.front_matter_val_new)
puts Fred::VERSION
end
end

end
end
end
Expand Down
Loading

0 comments on commit 8cb62dd

Please sign in to comment.