Compare commits
21 commits
Author | SHA1 | Date | |
---|---|---|---|
|
219c8b633f | ||
|
003cdd6f59 | ||
|
242a2730eb | ||
|
590f692094 | ||
26db7106a1 | |||
7f5af60757 | |||
|
fc7fbca090 | ||
f645c4d15e | |||
|
bf7486235f | ||
|
b2f02297e9 | ||
|
6954185ef1 | ||
|
29df35b196 | ||
21c8f0883a | |||
bef0389ce6 | |||
|
c6072d8ed3 | ||
|
52bdc5c615 | ||
4d7dcb2665 | |||
021b7ea8dd | |||
69b643309d | |||
cb9ae3ca5e | |||
430819cd81 |
7 changed files with 105 additions and 86 deletions
52
.forgejo/workflows/push-next.yml
Normal file
52
.forgejo/workflows/push-next.yml
Normal file
|
@ -0,0 +1,52 @@
|
|||
name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["next"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: docker
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
toolchain:
|
||||
- name: stable
|
||||
- name: nightly
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Format
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.3.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo fmt --all -- --check
|
||||
|
||||
# - name: Machete
|
||||
# uses: https://github.com/bnjbvr/cargo-machete@v0.6.2
|
||||
|
||||
- name: Clippy
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.3.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo clippy
|
||||
|
||||
- name: Build
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.3.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo build
|
||||
|
||||
- name: Test
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.3.0
|
||||
with:
|
||||
args: ${{ matrix.toolchain.name }} cargo test --no-fail-fast
|
||||
|
||||
- name: Integration
|
||||
uses: https://git.kemitix.net/kemitix/rust@v2.3.0
|
||||
with:
|
||||
args: ./test.sh
|
|
@ -1,5 +1,5 @@
|
|||
variables:
|
||||
- &rust_image "docker.io/rust:1.76"
|
||||
- &rust_image "docker.io/rust:1.82.0"
|
||||
- &slow_check_paths
|
||||
- path:
|
||||
# rust source code
|
||||
|
@ -14,28 +14,18 @@ variables:
|
|||
- ".woodpecker.yml"
|
||||
|
||||
steps:
|
||||
|
||||
toml_fmt:
|
||||
image: docker.io/tamasfe/taplo:0.8.1
|
||||
image: docker.io/tamasfe/taplo:0.9.3
|
||||
commands:
|
||||
- taplo format --check
|
||||
|
||||
|
||||
cargo_fmt:
|
||||
image: docker.io/rustlang/rust:nightly
|
||||
environment:
|
||||
# store cargo data in repo folder so that it gets cached between steps
|
||||
CARGO_HOME: .cargo_home
|
||||
commands:
|
||||
- rustup component add rustfmt
|
||||
- cargo fmt --check
|
||||
|
||||
cargo_machete:
|
||||
image: *rust_image
|
||||
commands:
|
||||
- wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz
|
||||
- tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz
|
||||
- cp cargo-binstall /usr/local/cargo/bin
|
||||
- rm cargo-binstall-x86_64-unknown-linux-musl.tgz
|
||||
- mv cargo-binstall /usr/local/cargo/bin
|
||||
- cargo binstall -y cargo-machete
|
||||
- cargo machete
|
||||
|
||||
|
@ -46,51 +36,11 @@ steps:
|
|||
- IGNORED=$(git ls-files --cached -i --exclude-standard)
|
||||
- if [[ "$IGNORED" ]]; then echo "Ignored files present:\n$IGNORED\n"; exit 1; fi
|
||||
|
||||
check:
|
||||
image: *rust_image
|
||||
environment:
|
||||
CARGO_HOME: .cargo_home
|
||||
commands:
|
||||
- cargo check
|
||||
when: *slow_check_paths
|
||||
|
||||
cargo_clippy:
|
||||
image: *rust_image
|
||||
environment:
|
||||
CARGO_HOME: .cargo_home
|
||||
commands:
|
||||
- rustup component add clippy
|
||||
- cargo clippy --tests --all-targets -- -D warnings
|
||||
when: *slow_check_paths
|
||||
|
||||
cargo_build:
|
||||
image: *rust_image
|
||||
environment:
|
||||
CARGO_HOME: .cargo_home
|
||||
commands:
|
||||
- cargo build
|
||||
- mv target/debug/skip target/skip
|
||||
when: *slow_check_paths
|
||||
|
||||
cargo_test:
|
||||
image: *rust_image
|
||||
environment:
|
||||
RUST_BACKTRACE: "1"
|
||||
CARGO_HOME: .cargo_home
|
||||
commands:
|
||||
- cargo test --no-fail-fast
|
||||
when: *slow_check_paths
|
||||
|
||||
integration_test:
|
||||
image: *rust_image
|
||||
commands:
|
||||
- ./test.sh
|
||||
|
||||
publish_to_crates_io:
|
||||
image: *rust_image
|
||||
commands:
|
||||
- cargo login "$CARGO_REGISTRY_TOKEN"
|
||||
- cargo publish --registry crates-io --no-verify --allow-branch "${CI_COMMIT_TAG}" --yes
|
||||
secrets: [cargo_api_token]
|
||||
- cargo publish --registry crates-io --no-verify
|
||||
secrets: [cargo_registry_token]
|
||||
when:
|
||||
event: tag
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -122,7 +122,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "skip"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -1,7 +1,15 @@
|
|||
[package]
|
||||
name = "skip"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
authors = ["Paul Campbell <pcampbell@kemitix.net>"]
|
||||
categories = ["command-line-utilities"]
|
||||
description = "Skip lines in a file"
|
||||
license = "MIT"
|
||||
repository = "https://git.kemitix.net/kemitix/skip"
|
||||
keywords = ["skip", "lines", "file", "text", "utility"]
|
||||
rust-version = "1.74.1"
|
||||
exclude = [".cargo_home"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -2,13 +2,17 @@
|
|||
|
||||
Skip part of a file.
|
||||
|
||||
As `head` will show the top of a file after a number of line,
|
||||
As `head` will show the top of a file up-to a number of line,
|
||||
so `skip` will do the opposite, and not show the top of the file,
|
||||
but will show the rest.
|
||||
|
||||
Additionally, it can check for whole lines matching,
|
||||
or for a token being present on the line.
|
||||
|
||||
N.B.: The `skip` crate used to be an implementation of [Skip list](https://en.wikipedia.org/wiki/Skip_list),
|
||||
by [Luo Jia / Zhouqi Jiang](https://github.com/luojia65) ([source](https://github.com/luojia65/skip)).
|
||||
That crate will be republished as [skip-list](https://crates.io/crates/skip-list) (soon).
|
||||
|
||||
## Usage
|
||||
|
||||
### Skip a fixed number of lines
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
"extends": ["config:recommended"],
|
||||
"packageRules": [
|
||||
{
|
||||
"matchManagers": ["cargo"],
|
||||
"rangeStrategy": "replace"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
51
test.sh
51
test.sh
|
@ -5,37 +5,38 @@ set -e
|
|||
echo "PWD: $PWD"
|
||||
ls -l
|
||||
ls -l target
|
||||
SKIP="./target/skip"
|
||||
SKIP="./target/debug/skip"
|
||||
DIFF="diff -u --color"
|
||||
|
||||
if test ! -x $SKIP ; then
|
||||
echo "File missing: $SKIP - try 'cargo build'"
|
||||
exit 1
|
||||
if test ! -x $SKIP; then
|
||||
echo "File missing: $SKIP - try 'cargo build'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "> skip a line when reading from stdin"
|
||||
INPUT=$(cat<<EOF
|
||||
INPUT=$(
|
||||
cat <<EOF
|
||||
line 1
|
||||
line 2
|
||||
EOF
|
||||
)
|
||||
echo "line 2" > test.expect
|
||||
echo "$INPUT" | $SKIP 1 > test.out
|
||||
echo "line 2" >test.expect
|
||||
echo "$INPUT" | $SKIP 1 >test.out
|
||||
$DIFF test.expect test.out
|
||||
rm test.expect test.out
|
||||
|
||||
echo "> skip a line when reading from a file"
|
||||
cat<<EOF > test.in
|
||||
cat <<EOF >test.in
|
||||
line 1
|
||||
line 2
|
||||
EOF
|
||||
echo "line 2" > test.expect
|
||||
$SKIP 1 test.in > test.out
|
||||
echo "line 2" >test.expect
|
||||
$SKIP 1 test.in >test.out
|
||||
$DIFF test.expect test.out
|
||||
rm test.expect test.out
|
||||
|
||||
echo "> skip until 2 matching lines seen"
|
||||
cat<<EOF > test.in
|
||||
cat <<EOF >test.in
|
||||
alpha
|
||||
beta
|
||||
alpha
|
||||
|
@ -43,17 +44,17 @@ alpha
|
|||
gamma
|
||||
alpha
|
||||
EOF
|
||||
cat<<EOF > test.expect
|
||||
cat <<EOF >test.expect
|
||||
alpha
|
||||
gamma
|
||||
alpha
|
||||
EOF
|
||||
$SKIP 2 test.in --line alpha > test.out
|
||||
$SKIP 2 test.in --line alpha >test.out
|
||||
$DIFF test.expect test.out
|
||||
rm test.in test.expect test.out
|
||||
|
||||
echo "> skip lines until 2 tokens seen"
|
||||
cat<<EOF > test.in
|
||||
cat <<EOF >test.in
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit,
|
||||
sed do eiusmod tempor incididunt
|
||||
|
@ -63,18 +64,18 @@ quis nostrud exercitation ullamco
|
|||
laboris nisi ut aliquip ex ea
|
||||
commodo consequat.
|
||||
EOF
|
||||
cat<<EOF > test.expect
|
||||
cat <<EOF >test.expect
|
||||
Ut enim ad minim veniam,
|
||||
quis nostrud exercitation ullamco
|
||||
laboris nisi ut aliquip ex ea
|
||||
commodo consequat.
|
||||
EOF
|
||||
$SKIP 2 test.in --token dolor > test.out
|
||||
$SKIP 2 test.in --token dolor >test.out
|
||||
$DIFF test.expect test.out
|
||||
rm test.in test.expect test.out
|
||||
|
||||
echo "> handle unknown parameter with simple error message"
|
||||
cat<<EOF > test.expect.err
|
||||
cat <<EOF >test.expect.err
|
||||
error: unexpected argument '--foo' found
|
||||
|
||||
tip: to pass '--foo' as a value, use '-- --foo'
|
||||
|
@ -83,17 +84,17 @@ Usage: skip [OPTIONS] <LINES> [FILE]
|
|||
|
||||
For more information, try '--help'.
|
||||
EOF
|
||||
cat<<EOF > test.expect
|
||||
cat <<EOF >test.expect
|
||||
EOF
|
||||
touch test.out test.err
|
||||
$SKIP --foo > test.out 2> test.err || true
|
||||
$SKIP --foo >test.out 2>test.err || true
|
||||
$DIFF test.expect test.out
|
||||
$DIFF test.expect.err test.err
|
||||
rm test.expect test.out
|
||||
rm test.expect.err test.err
|
||||
|
||||
echo "> handle ignore-extra when token is missing"
|
||||
cat<<EOF > test.expect.err
|
||||
cat <<EOF >test.expect.err
|
||||
error: the following required arguments were not provided:
|
||||
--token <TOKEN>
|
||||
<LINES>
|
||||
|
@ -102,17 +103,17 @@ Usage: skip --ignore-extras --token <TOKEN> <LINES> [FILE]
|
|||
|
||||
For more information, try '--help'.
|
||||
EOF
|
||||
cat<<EOF > test.expect
|
||||
cat <<EOF >test.expect
|
||||
EOF
|
||||
touch test.out test.err
|
||||
$SKIP --ignore-extras > test.out 2> test.err || true
|
||||
$SKIP --ignore-extras >test.out 2>test.err || true
|
||||
$DIFF test.expect test.out
|
||||
$DIFF test.expect.err test.err
|
||||
rm test.expect test.out
|
||||
rm test.expect.err test.err
|
||||
|
||||
echo "> skip lines until 4 tokens seen - ignored extra tokens on same line"
|
||||
cat<<EOF > test.in
|
||||
cat <<EOF >test.in
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit,
|
||||
sed do eiusmod tempor incididunt
|
||||
|
@ -122,12 +123,12 @@ quis nostrud exercitation ullamco
|
|||
laboris nisi ut aliquip ex ea
|
||||
commodo consequat.
|
||||
EOF
|
||||
cat<<EOF > test.expect
|
||||
cat <<EOF >test.expect
|
||||
quis nostrud exercitation ullamco
|
||||
laboris nisi ut aliquip ex ea
|
||||
commodo consequat.
|
||||
EOF
|
||||
$SKIP 4 test.in --token m --ignore-extras > test.out
|
||||
$SKIP 4 test.in --token m --ignore-extras >test.out
|
||||
$DIFF test.expect test.out
|
||||
rm test.in test.expect test.out
|
||||
|
||||
|
|
Loading…
Reference in a new issue