<commit_before>#[macro_use]
extern crate clap;

#[macro_use]
extern crate serde_derive;

extern crate serde_json;

mod timesheet;

fn main() {
    let mut session = timesheet::Session::new();

    /* Handle command line arguments with clap */
    let matches = clap_app!(trk =>
        (version: "0.1")
        (author: "<NAME>. <<EMAIL>>")
        (about: "Create timesheets from git history and meta info")
            (@arg CONFIG: -c --config +takes_value "[UNUSED] Sets a custom config file")
            (@arg debug: -d ... "[UNUSED] Sets the level of debugging information")

            (@subcommand beginperiod =>
                (about: "Begin period")
                (version: "0.1")
                (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand beginsession =>
                    (about: "Begin session")
                    (version: "0.1")
                    (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand endperiod =>
                (about: "End period")
                (version: "0.1")
                (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand endsession =>
                (about: "End session")
                (version: "0.1")
                (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand pause =>
                (about: "Pause current session")
                (version: "0.1")
                (author: "<EMAIL>")
            )
            (@subcommand proceed =>
                (about: "Proceed with currently paused session")
                (version: "0.1")
                (author: "<EMAIL>")
            )
            (@subcommand meta =>
                (about: "Proceed with currently paused session")
                (version: "0.1")
                (author: "<EMAIL>")
                (@arg text: +required "Meta information about work")
            )
            (@subcommand commit =>
                (about: "add a commit to the event list")
                (version: "0.1")
                (author: "<EMAIL>")
                (@arg hash: +required "Commit hash id")
            )
            (@subcommand branch =>
                (about: "add a topic to the event list")
                (version: "0.1")
                (author: "<EMAIL>")
                (@arg name: +required "New branch name")
            )
       )
            .get_matches();

    // Gets a value for config if supplied by user, or defaults to "default.conf"
    let config = matches.value_of("config").unwrap_or("default.conf");
    println!("Value for config: {}", config);

    // You can handle information about subcommands by requesting their matches by name
    // TODO: Find a way to do this in a better way than an if sequence
    if matches.is_present("beginperiod") {
        session.push_event(timesheet::Event::BeginPeriod)
    }
    if matches.is_present("beginsession") {
        session.push_event(timesheet::Event::BeginSession)
    }
    if matches.is_present("endperiod") {
        session.push_event(timesheet::Event::EndPeriod)
    }
    if matches.is_present("endsession") {
        session.push_event(timesheet::Event::EndSession)
    }

    if matches.is_present("pause") {
        session.push_event(timesheet::Event::Pause)
    }
    if matches.is_present("proceed") {
        session.push_event(timesheet::Event::Proceed)
    }

    match matches.subcommand() { 
        ("meta", Some(sub_input)) => {
            let metatext = sub_input.value_of("text").unwrap();
            session.push_event(timesheet::Event::Meta { text: metatext.to_string() });
        }
        ("commit", Some(sub_input)) => {
            let commit_hash = sub_input.value_of("hash").unwrap();
            let hash_parsed = u64::from_str_radix(commit_hash, 16).unwrap();
            session.push_event(timesheet::Event::Commit { hash: hash_parsed });
        }
        ("branch", Some(sub_input)) => {
            let branch_name = sub_input.value_of("name").unwrap();
            session.push_event(timesheet::Event::Branch { name: branch_name.to_string() });
        }
        _ => {}
    }
    println!("{:?}", session);

    // Convert the Point to a JSON string.
    let serialized = serde_json::to_string(&session).unwrap();

    // Prints serialized = {"x":1,"y":2}
    println!("serialized = {}", serialized);

    // Convert the JSON string back to a Point.
    let deserialized: timesheet::Session = serde_json::from_str(&serialized).unwrap();

    // Prints deserialized = Point { x: 1, y: 2 }
    println!("deserialized = {:?}", deserialized);
}<commit_msg>improve subcommand and arg matching<commit_after>#[macro_use]
extern crate clap;

#[macro_use]
extern crate serde_derive;

extern crate serde_json;

mod timesheet;

fn main() {
    let mut session = timesheet::Session::new();

    /* Handle command line arguments with clap */
    let matches = clap_app!(trk =>
        (version: "0.1")
        (author: "<NAME>. <<EMAIL>>")
        (about: "Create timesheets from git history and meta info")
            (@arg CONFIG: -c --config +takes_value "[UNUSED] Sets a custom config file")
            (@arg debug: -d ... "[UNUSED] Sets the level of debugging information")

            (@subcommand beginperiod =>
                (about: "Begin period")
                (version: "0.1")
                (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand beginsession =>
                    (about: "Begin session")
                    (version: "0.1")
                    (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand endperiod =>
                (about: "End period")
                (version: "0.1")
                (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand endsession =>
                (about: "End session")
                (version: "0.1")
                (author:  "<NAME>. <<EMAIL>>")
            )
            (@subcommand pause =>
                (about: "Pause current session")
                (version: "0.1")
                (author: "<EMAIL>")
            )
            (@subcommand proceed =>
                (about: "Proceed with currently paused session")
                (version: "0.1")
                (author: "<EMAIL>")
            )
            (@subcommand meta =>
                (about: "Proceed with currently paused session")
                (version: "0.1")
                (author: "<EMAIL>")
                (@arg text: +required "Meta information about work")
            )
            (@subcommand commit =>
                (about: "add a commit to the event list")
                (version: "0.1")
                (author: "<EMAIL>")
                (@arg hash: +required "Commit hash id")
            )
            (@subcommand branch =>
                (about: "add a topic to the event list")
                (version: "0.1")
                (author: "<EMAIL>")
                (@arg name: +required "New branch name")
            )
       )
            .get_matches();

    // Gets a value for config if supplied by user, or defaults to "default.conf"
    let config = matches.value_of("config").unwrap_or("default.conf");
    println!("[UNUSED] Value for config: {}", config);

    match matches.subcommand() { 
        ("beginperiod", Some(..)) => {
            session.push_event(timesheet::Event::BeginPeriod)
        }
        ("endperiod", Some(..)) => {
            session.push_event(timesheet::Event::EndPeriod)
        }
        ("beginsession", Some(..)) => {
            session.push_event(timesheet::Event::BeginSession)
        }
        ("endsession", Some(..)) => {
            session.push_event(timesheet::Event::EndSession)
        }
        ("pause", Some(..)) => {
            session.push_event(timesheet::Event::Pause)
        }
        ("proceed", Some(..)) => {
            session.push_event(timesheet::Event::Proceed)
        }
        ("meta", Some(sub_input)) => {
            let metatext = sub_input.value_of("text").unwrap();
            session.push_event(timesheet::Event::Meta { text: metatext.to_string() });
        }
        ("commit", Some(sub_input)) => {
            let commit_hash = sub_input.value_of("hash").unwrap();
            let hash_parsed = u64::from_str_radix(commit_hash, 16).unwrap();
            session.push_event(timesheet::Event::Commit { hash: hash_parsed });
        }
        ("branch", Some(sub_input)) => {
            let branch_name = sub_input.value_of("name").unwrap();
            session.push_event(timesheet::Event::Branch { name: branch_name.to_string() });
        }
        _ => {}
    }

    // Convert the session to a JSON string.
    let serialized = serde_json::to_string(&session).unwrap();

    // Prints serialized session
    println!("serialized = {}", serialized);

    // Convert the JSON string back to a Session.
    let deserialized: timesheet::Session = serde_json::from_str(&serialized).unwrap();

    // Prints deserialized Session
    println!("deserialized = {:?}", deserialized);
}
{'fraction_non_alphanumeric': 0.14599511870423784, 'fraction_numerical': 0.005768804082538274, 'mean_word_length': 1.8286790084719171, 'pattern_counts': {'":': 2, '<': 43, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3541774', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2499, 'n_words': 608}