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

refactor: support git url for add #54

Merged
merged 8 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Commands:
list List all templates
remove Remove specified templates
mv Rename a template
add Add templates from GitHub repository
add Add template from GitHub repository
create Copy the template folder to the specified directory
token Configure or display your GitHub personal access token
help Print this message or the help of the given subcommand(s)
Expand All @@ -48,6 +48,31 @@ Options:

## Example

### Basic

```bash
sca add user/repo

# GitHub url
sca add https://github.com/user/repo.git

# subdir
sca add user/repo --subdir /path/to/dir

# branch
sca add user/repo --branch branch

# tag
sca add user/repo --tag tag

# commit
sca add user/repo --commit e763a43519ea4c209df2452c6e2a5b7dffdfdd3d
```

```bash
sca create repo
```

### Proxy support

```bash
Expand Down
92 changes: 90 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum Command {
/// Rename a template
Mv(MvArgs),

/// Add templates from GitHub repository
/// Add template from GitHub repository
Add(AddArgs),

/// Copy the template folder to the specified directory
Expand Down Expand Up @@ -72,8 +72,9 @@ pub struct MvArgs {
}

#[derive(Args, Debug)]
#[cfg_attr(test, derive(Clone))]
pub struct AddArgs {
/// owner/name/.../subdir?(branch|tag|commit)=...
/// owner/name/.../subdir
pub repository: String,

/// The depth to go when recursing repository
Expand All @@ -90,6 +91,22 @@ pub struct AddArgs {
/// subdir will be used as the name
#[arg(long)]
pub name: Option<String>,

/// Specify sub directory
#[arg(long)]
pub subdir: Option<String>,

/// Specify branch
#[arg(long)]
pub branch: Option<String>,

/// Specify tag
#[arg(long)]
pub tag: Option<String>,

/// Specify commit
#[arg(long)]
pub commit: Option<String>,
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -126,6 +143,77 @@ pub struct UninstallArgs {
pub keep_data: bool,
}

#[cfg(test)]
pub mod test_utils {
use super::AddArgs;

pub struct AddArgsMock {
args: AddArgs,
}

impl AddArgsMock {
pub fn new() -> Self {
Self {
args: AddArgs {
repository: "".to_string(),
depth: 0,
name: None,
subdir: None,
branch: None,
tag: None,
commit: None,
},
}
}

pub fn build(&self) -> AddArgs {
self.args.clone()
}

pub fn repository(&mut self, repository: &str) -> &mut Self {
self.args.repository = repository.to_string();

self
}

pub fn depth(&mut self, depth: u8) -> &mut Self {
self.args.depth = depth;

self
}

pub fn name(&mut self, name: &str) -> &mut Self {
self.args.name = Some(name.to_string());

self
}

pub fn subdir(&mut self, subdir: &str) -> &mut Self {
self.args.subdir = Some(subdir.to_string());

self
}

pub fn branch(&mut self, branch: &str) -> &mut Self {
self.args.branch = Some(branch.to_string());

self
}

pub fn tag(&mut self, tag: &str) -> &mut Self {
self.args.tag = Some(tag.to_string());

self
}

pub fn commit(&mut self, commit: &str) -> &mut Self {
self.args.commit = Some(commit.to_string());

self
}
}
}

#[cfg(test)]
mod tests {
use clap::CommandFactory;
Expand Down
13 changes: 0 additions & 13 deletions src/github_api/gql.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::debug;

#[derive(Serialize)]
pub struct GraphQLQuery {
pub query: &'static str,
pub variables: String,
}

impl GraphQLQuery {
pub fn new(query: &'static str, variables: String) -> Self {
debug!("GraphQL variables json: {}", variables);

Self {
query,
variables,
}
}
}

#[derive(Deserialize, Serialize, Debug)]
pub struct GraphQLResponse<T>
where
Expand Down