Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive completion arguments #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/shrs_derive_completion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ extern crate derive_builder;

extern crate proc_macro;

use std::marker::PhantomData;

use quote::quote;
use shrs::line::completion::Action;
use syn::{parse_macro_input, Attribute, Fields, Item, ItemStruct, LitChar, LitStr, Meta};
use thiserror::__private::DisplayAsDisplay;

Expand Down Expand Up @@ -35,6 +38,13 @@ struct Flag {
short: Option<char>,
}

/// Information on type of argument
// TODO include default function for generating completions based on type?
// ie: files, ssh
struct Arg {
action: Action,
}

#[derive(thiserror::Error, Debug)]
enum Error {
#[error("Could not applied on unnamed field")]
Expand Down Expand Up @@ -67,6 +77,7 @@ fn impl_struct(item: ItemStruct) -> Result<proc_macro2::TokenStream, Error> {

// check if field is marked as flag
for attr in field.attrs.iter() {
// handle #[flag(..)]
if attr.path().is_ident("flag") {
// Default long flag name is name of field
let mut flag = FlagBuilder::default();
Expand Down Expand Up @@ -98,6 +109,8 @@ fn impl_struct(item: ItemStruct) -> Result<proc_macro2::TokenStream, Error> {
})
.unwrap();
flags.push(flag.build().unwrap());
} else if attr.path().is_ident("arg") {
// handle #[arg(..)]
}
}
}
Expand Down