Skip to content

Commit

Permalink
Add env subcommand to print path to config
Browse files Browse the repository at this point in the history
  • Loading branch information
DoumanAsh committed Nov 26, 2017
1 parent 3055df0 commit da62406
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fie"
version = "0.4.0"
version = "0.5.0"
authors = ["Douman <[email protected]>"]
repository = "https://github.com/DoumanAsh/fie"
description = "Small and cute twitter app."
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Use [example](fie.toml) as reference.
## Usage

```
Douman <[email protected]>
Small and cute twitter app.
USAGE:
Expand All @@ -37,8 +35,9 @@ FLAGS:
-V, --version Prints version information
SUBCOMMANDS:
env Prints information about app environment.
help Prints this message or the help of the given subcommand(s)
post Creates new tweet
post Creates new tweet.
```

### post
Expand All @@ -63,4 +62,20 @@ ARGS:
<message> Message content
```

### env

Prints information about app's environment.

```
Prints information about app environment.
USAGE:
fie.exe env [SUBCOMMAND]
FLAGS:
-h, --help Prints help information
SUBCOMMANDS:
config Prints path to config file.
help Prints this message or the help of the given subcommand(s)
```
40 changes: 34 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const ABOUT: &'static str = "
Small and cute twitter app.";

#[inline(always)]
fn new_command() -> App<'static, 'static> {
SubCommand::with_name("post").about("Creates new tweet")
fn post_command() -> App<'static, 'static> {
SubCommand::with_name("post").about("Creates new tweet.")
.arg(arg("message").required(true)
.help("Message content"))
.arg(arg("tag").short("t")
Expand All @@ -45,19 +45,39 @@ fn new_command() -> App<'static, 'static> {
.help("Adds image to post. Normally up to 4."))
}

#[inline(always)]
fn env_config_command() -> App<'static, 'static> {
SubCommand::with_name("config").about("Prints path to config file.")
}

#[inline(always)]
fn env_command() -> App<'static, 'static> {
SubCommand::with_name("env").about("Prints information about app environment.")
.setting(AppSettings::ArgRequiredElseHelp)
.subcommand(env_config_command())
}

pub fn parser() -> App<'static, 'static> {
App::new(NAME).about(ABOUT)
.author(AUTHOR)
.version(VERSION)
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::VersionlessSubcommands)
.subcommand(new_command())
.arg(flag("gab").help("Use gab.ai. By default all social medias are used unless flag is specified."))
.arg(flag("twitter").help("Use Twitter. By default all social medias are used unless flag is specified."))
.arg(flag("minds").help("Use Minds.com. By default all social medias are used unless flag is specified."))
.subcommand(post_command())
.subcommand(env_command())

}

#[derive(Debug)]
///Env subcommand variants
pub enum EnvCommand {
///Prints configuration file.
Config
}

#[derive(Debug)]
///Command representation with all its arguments.
pub enum Commands {
Expand All @@ -66,9 +86,11 @@ pub enum Commands {
///# Parameters:
///
///* First - Text.
///* Second - Tags.
///* Third - Image to attach.
Post(String, Option<Vec<String>>)
///* Second - Images to attach.
Post(String, Option<Vec<String>>),
///Prints environment information.
Env(EnvCommand)

}

impl Commands {
Expand All @@ -87,6 +109,12 @@ impl Commands {

Commands::Post(message, image)
},
"env" => {
match matches.subcommand() {
("config", _) => Commands::Env(EnvCommand::Config),
_ => unimplemented!()
}
}
_ => unimplemented!()
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ fn init_api<'a>(mut tokio_core: &mut Core, http: &'a api::http::HttpClient, conf
}

fn run() -> Result<i32, String> {
let config = config::Config::from_file(&utils::get_config())?;
let config_path = utils::get_config();
let config = config::Config::from_file(&config_path)?;
let args = cli::Args::new(config.platforms)?;
let config = ApiConfigs {
gab: config.gab,
Expand Down Expand Up @@ -141,6 +142,11 @@ fn run() -> Result<i32, String> {
}

tokio_core.run(futures::future::join_all(jobs)).unwrap();
},
cli::Commands::Env(env) => {
match env {
cli::EnvCommand::Config => println!("{}", config_path.display()),
}
}
};

Expand Down

0 comments on commit da62406

Please sign in to comment.