diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-09 11:37:57 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-09 11:37:57 +0100 |
commit | 2851ca7aa80da00e8c2178a5c60c97b006b36f7f (patch) | |
tree | 07c9a8d82f741e72b389fa6def21f1b3d5d4b303 /cli/src/profile.rs | |
parent | d2db69cfc4e239a73aa24543b781031b5ff63611 (diff) | |
parent | 03b7feebdb56cd014d881faf29de64f681a038a6 (diff) |
Merge branch 'profile-post-text'
Diffstat (limited to 'cli/src/profile.rs')
-rw-r--r-- | cli/src/profile.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cli/src/profile.rs b/cli/src/profile.rs index 412f143..ca59c2b 100644 --- a/cli/src/profile.rs +++ b/cli/src/profile.rs @@ -13,6 +13,7 @@ pub async fn profile(matches: &ArgMatches) -> Result<()> { match matches.subcommand() { Some(("create", m)) => profile_create(m).await, Some(("serve", m)) => profile_serve(m).await, + Some(("post", m)) => profile_post(m).await, _ => unimplemented!(), } } @@ -67,3 +68,30 @@ async fn profile_serve(matches: &ArgMatches) -> Result<()> { log::info!("Shutting down..."); profile.exit().await } + +async fn profile_post(matches: &ArgMatches) -> Result<()> { + let text = match matches.value_of("text") { + Some(text) => String::from(text), + None => if matches.is_present("editor") { + editor_input::input_from_editor("")? + } else { + unreachable!() + } + }; + let name = matches.value_of("name").map(String::from).unwrap(); // required + let state_dir = Profile::state_dir_path(&name)?; + log::info!("Creating '{}' in {}", name, state_dir.display()); + + log::info!("Loading '{}' from {}", name, state_dir.display()); + let mut profile = Profile::load(Config::default(), &name).await?; + log::info!("Profile loaded"); + log::info!("Profile HEAD = {:?}", profile.head()); + + log::info!("Posting text..."); + profile.post_text(text).await?; + log::info!("Posting text finished"); + profile.save().await?; + log::info!("Saving profile state to disk finished"); + profile.exit().await +} + |