/*
==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--

touch-als

Copyright (C) 2021, 2024  Anonymous



This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
*/

//! # Command options

use {
    core::{
        fmt::{self, Display, Formatter},
        str::FromStr,
    },
    std::io::{Error, ErrorKind},
};

/// # Command options
#[derive(Debug)]
pub (crate) enum CmdOption {

    /// # On success
    OnSuccess,

    /// # On failure
    OnFailure

}

impl Display for CmdOption {

    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        f.write_str(match self {
            CmdOption::OnSuccess => "on-success",
            CmdOption::OnFailure => "on-failure",
        })
    }

}

impl FromStr for CmdOption {

    type Err = Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if s.eq_ignore_ascii_case("on-success") {
            Ok(CmdOption::OnSuccess)
        } else if s.eq_ignore_ascii_case("on-failure") {
            Ok(CmdOption::OnFailure)
        } else {
            Err(Error::new(ErrorKind::InvalidInput, format!("Unknown option: {:?}", s)))
        }
    }

}