2 unstable releases

Uses old Rust 2015

0.3.0 Mar 10, 2018
0.2.0 Feb 26, 2018
0.1.0 Feb 26, 2018

#30 in #parser-combinators

MIT license

12KB
281 lines

cronenberg Build Status

simple cron command entry parser

cronenberg provides two core components

  • TimeItem: An enum that represents cron command time or date field
  • CronItem: A struct that represents cron command entry, for example, * * 5-7 1,2,5 8 sudo rm -rf /

Installation

cronenberg is available on crates.io and can be included in your Cargo enabled project like this:

[dependencies]
cronenberg = "0.2.0"

Then include it in your code like this:

extern crate cronenberg;

Example

extern crate cronenberg;

use cronenberg::cron_item::CronItem;
use cronenberg::cron_item::TimeItem::*;
use std::str::FromStr;
use std::string::ToString;

let s = "* * 5-7 1,2,5 8 ls -la";
assert_eq!(
    CronItem::from_str(s).unwrap(),
    CronItem {
        minute: AllValues,
        hour: AllValues,
        day_of_month: Interval((5, 7)),
        month: MultipleValues(vec![1, 2, 5]),
        day_of_week: SingleValue(8),
        command: String::from("ls -la"),
    }
);

let cron_item = CronItem {
    minute: MultipleValues(vec![1, 10]),
    hour: Interval((1, 4)),
    day_of_month: Interval((1, 11)),
    month: MultipleValues(vec![1, 2, 5]),
    day_of_week: AllValues,
    command: String::from("pwd"),
};
assert_eq!("1,10 1-4 1-11 1,2,5 * pwd", cron_item.to_string());

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

Ayrat Badykov (@ayrat555)

License

cronenberg is released under the MIT License.

Dependencies

~720KB
~14K SLoC