<commit_before>#[macro_use]
extern crate clap;

#[macro_use]
extern crate log;
extern crate env_logger;

use clap::{Arg, App, SubCommand};
use std::env;
use std::io;
use std::io::prelude::*;

const GANDI_URL_PROD: &'static str = "https://rpc.gandi.net/";

trait GandiAPI {
    fn check(&self, record: &str) -> Option<&str>;
    fn update(&self, record: &str, ipAddr: &str);
    fn create(&self, record: &str, ipAddr: &str);
}

struct GandiAPIImpl;

impl GandiAPI for GandiAPIImpl {
    fn check(&self, record: &str) -> Option<&str> {
        unimplemented!();
    }

    fn update(&self, record: &str, ipAddr: &str) {
        unimplemented!();
    }

    fn create(&self, record: &str, ipAddr: &str) {
        unimplemented!();
    }
}

fn main() {
    let matches = App::new("gdu")
        .version(&crate_version!()[..])
        .author("<NAME> <<EMAIL>>")
        .about("Gandi DNS updater, useful to reflect your dynamic IP address to your Gandi DNS zone file")
        .args_from_usage(
            "-a --apikey=[apikey] 'Your API key provided by Gandi'
            -d --domain=[domain] 'The domain name whose active zonefile will be updated, e.g. \"domain.com\"'
            -n --dry-run 'Dry run, don't really update Gandi zone file'
            [verbose]... -v 'Verbose mode'")
        .arg(Arg::with_name("record_name")
            .help("Name of the A record to update or create (without domain)")
            .index(1)
            .required(true)
            .multiple(false))
        .get_matches();

    // Init logging to DEBUG only if user requires it
    if matches.is_present("verbose") {
        env::set_var("RUST_LOG", "DEBUG");
    }
    env_logger::init().unwrap();

    let apikey = matches.value_of("apikey").unwrap();
    debug!("Using apikey: {}", apikey);

    let domain = matches.value_of("domain").unwrap();
    debug!("Using domain: {}", domain);

    let record_name = matches.value_of("record_name").unwrap();
    debug!("Using record name: {}", record_name);

    let dry_run = matches.is_present("dry-run");
    debug!("Dry run: {}", dry_run);

//    let stdin = io::stdin();
//    for line in stdin.lock().lines() {
//        println!("{}", line.unwrap());
//    }

    let detectedIpAddr = "todo my ip";

    let gandi_api = GandiAPIImpl;

    let maybeChecked = gandi_api.check(record_name);

    match maybeChecked {
        Some(ipAddr) => {
            if (ipAddr != detectedIpAddr) {
                gandi_api.update(record_name, ipAddr);
            }
        }
        None => gandi_api.create(record_name, detectedIpAddr)<commit_msg>RPC method names refactoring<commit_after>#[macro_use]
extern crate clap;

#[macro_use]
extern crate log;
extern crate env_logger;

use clap::{Arg, App, SubCommand};
use std::env;
use std::io;
use std::io::prelude::*;

const GANDI_URL_PROD: &'static str = "https://rpc.gandi.net/";

trait GandiAPI {
    fn isRecordAlreadyDeclared(&self, record: &str) -> Option<&str>;
    fn updateRecord(&self, record: &str, ipAddr: &str);
    fn createRecord(&self, record: &str, ipAddr: &str);
}

struct GandiAPIImpl;

impl GandiAPI for GandiAPIImpl {
    fn isRecordAlreadyDeclared(&self, record: &str) -> Option<&str> {
        unimplemented!();
    }

    fn updateRecord(&self, record: &str, ipAddr: &str) {
        unimplemented!();
    }

    fn createRecord(&self, record: &str, ipAddr: &str) {
        unimplemented!();
    }
}

fn main() {
    let matches = App::new("gdu")
        .version(&crate_version!()[..])
        .author("<NAME> <<EMAIL>>")
        .about("Gandi DNS updater, useful to reflect your dynamic IP address to your Gandi DNS zone file.\nIP address is read from stdin.")
        .args_from_usage(
            "-a --apikey=[apikey] 'Your API key provided by Gandi'
            -d --domain=[domain] 'The domain name whose active zonefile will be updated, e.g. \"domain.com\"'
            -n --dry-run 'Dry run, don't really update Gandi zone file'
            [verbose]... -v 'Verbose mode'")
        .arg(Arg::with_name("record_name")
            .help("Name of the A record to update or create (without domain)")
            .index(1)
            .required(true)
            .multiple(false))
        .get_matches();

    // Init logging to DEBUG only if user requires it
    if matches.is_present("verbose") {
        env::set_var("RUST_LOG", "DEBUG");
    }
    env_logger::init().unwrap();

    let apikey = matches.value_of("apikey").unwrap();
    debug!("Using apikey: {}", apikey);

    let domain = matches.value_of("domain").unwrap();
    debug!("Using domain: {}", domain);

    let record_name = matches.value_of("record_name").unwrap();
    debug!("Using record name: {}", record_name);

    let dry_run = matches.is_present("dry-run");
    debug!("Dry run: {}", dry_run);

    let mut input = String::new();
    match io::stdin().read_line(&mut input) {
        Ok(n) => {
            println!("Input: {}", input);
        }
        Err(error) => println!("error: {}", error),
    }

    let detectedIpAddr = input.trim();

    let gandi_api = GandiAPIImpl;

    let maybeChecked = gandi_api.isRecordAlreadyDeclared(record_name);

    match maybeChecked {
        Some(ipAddr) => {
            if ipAddr != detectedIpAddr {
                gandi_api.updateRecord(record_name, ipAddr);
            }
        }
        None => gandi_api.createRecord(record_name, detectedIpAddr)
{'fraction_non_alphanumeric': 0.15721984761196803, 'fraction_numerical': 0.00037167812674224123, 'mean_word_length': 2.724567474048443, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '6904555', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1741, 'n_words': 443}