Skip to content

Commit

Permalink
csplit: first implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkindahl committed Nov 14, 2019
1 parent 0ef17a3 commit 5b4e727
Show file tree
Hide file tree
Showing 23 changed files with 741 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"clear",
"coreutils_core",
"cut",
"csplit",
"date",
"du",
"dirname",
Expand Down
1 change: 1 addition & 0 deletions DragonflyBSD.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions FreeBSD.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions Fuchsia.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"basename",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions Haiku.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions Linux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions MacOS.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions NetBSD.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions OpenBSD.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions Solaris.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
1 change: 1 addition & 0 deletions Unix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"chroot",
"clear",
"cut",
"csplit",
"date",
"dirname",
"du",
Expand Down
13 changes: 13 additions & 0 deletions csplit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "csplit"
version = "0.1.0"
authors = ["Mats Kindahl <mats.kindahl@gmail.com>"]
build = "build.rs"
edition = "2018"

[dependencies]
clap = { version = "^2.33.0", features = ["yaml", "wrap_help"] }
regex = "^1.3.1"

[build-dependencies]
clap = { version = "^2.33.0", features = ["yaml"] }
19 changes: 19 additions & 0 deletions csplit/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::env;

use clap::{load_yaml, App, Shell};

fn main() {
let yaml = load_yaml!("src/csplit.yml");
let mut app = App::from_yaml(yaml);

let out_dir = match env::var("OUT_DIR") {
Ok(dir) => dir,
_ => return,
};

app.gen_completions("csplit", Shell::Zsh, out_dir.clone());
app.gen_completions("csplit", Shell::Fish, out_dir.clone());
app.gen_completions("csplit", Shell::Bash, out_dir.clone());
app.gen_completions("csplit", Shell::PowerShell, out_dir.clone());
app.gen_completions("csplit", Shell::Elvish, out_dir);
}
67 changes: 67 additions & 0 deletions csplit/src/csplit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: csplit
version: "0.1.0"
author: Mats Kindahl <mats.kindahl@gmail.com>
about: |-
Split FILE by each PATTERN into a series of files 'xx00', 'xx01',
...
A file name has to be provided, but if it is '-', input will read
from standard input.
The input will be split up to, but not including, the line that
matches PATTERN.
The number of bytes in each file will be displayed on standard
output with one line for each file.
args:
- FILE:
help: File to read, or '-' to read from standard input.
required: true
- PATTERN:
help: Patterns to use when splitting file.
multiple: true
long_help: |-
PATTERN can be any of:
INTEGER copy lines up to line number
/REGEXP/[OFFSET] copy lines up to line matching REGEXP
%REGEXP%[OFFSET] skip lines up to line matching REGEXP
{INTEGER} repeat preceeding pattern INTEGER times
{*} repeat preceeding pattern indefinitely
If an OFFSET is given it should be an integer, either
positive or negative. An offset without sign is assumed to
be positive.
- prefix:
long: prefix
short: f
value_name: PREFIX
default_value: xx
help: Prefix to use for written files.
- suffix-format:
long: suffix-format
short: b
value_name: FORMAT
help: Format to use for the file suffix. The default is '%02d'.
- keep:
long: keep-files
short: k
help: Do not remove output files on error.
- suppress:
long: suppress-matched
short: x
help: Suppress lines that match a PATTERN.
- digits:
long: digits
short: n
value_name: DIGITS
default_value: "2"
help: Use the given number of digits for output file name.
- silent:
long: quiet
long: silent
short: s
help: Do not print counts of output file sizes.
- elide-empty:
long: elide-empty-files
short: z
help: Remove empty output files.
Loading

0 comments on commit 5b4e727

Please sign in to comment.