pub struct GhClient { /* private fields */ }
Expand description
Main GitHub CLI client This is the entry point for all GitHub CLI operations
Implementations§
Source§impl GhClient
impl GhClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new GitHub CLI client with default settings
Examples found in repository?
examples/basic_usage.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5
6 // Check if gh CLI is installed
7 let version = client.check_installation()?;
8 println!("✓ GitHub CLI: {}", version.trim());
9
10 // List repositories
11 let repos = client.repo().list().limit(5).execute()?;
12 println!("{}", repos);
13
14 Ok(())
15}
More examples
examples/repo.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5 println!("Creating a new repository:");
6 match client
7 .repo()
8 .create("gh-cli-rs")
9 .description("A wrapper for GitHub CLI in Rust")
10 .public()
11 .with_readme()
12 .execute()
13 {
14 Ok(result) => println!("✓ Repository created: {}", result),
15 Err(e) => eprintln!("✗ Error: {}", e),
16 }
17
18 Ok(())
19}
examples/pr.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5
6 println!("Creating a pull request...");
7 match client
8 .pr()
9 .create()
10 .title("test PR created by gh_cli_rs")
11 .body("This PR adds a new feature\n\n## Changes\n- Added feature X\n- Fixed bug Y")
12 // the branches must exist in remote repo for the command to work
13 .base("main")
14 .head("feature-branch")
15 .draft()
16 .execute()
17 {
18 Ok(result) => println!("✓ PR created: {}", result),
19 Err(e) => eprintln!("✗ Error: {}", e),
20 }
21
22 println!("\n🔍 Viewing PR #1:");
23 match client.pr().view(1).execute() {
24 Ok(pr) => println!("{}", pr),
25 Err(e) => eprintln!("✗ Error: {}", e),
26 }
27
28 Ok(())
29}
Sourcepub fn builder() -> GhClientBuilder
pub fn builder() -> GhClientBuilder
Start building a custom GitHub CLI client
Sourcepub fn check_installation(&self) -> Result<String>
pub fn check_installation(&self) -> Result<String>
Check if GitHub CLI is installed
Examples found in repository?
examples/basic_usage.rs (line 7)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5
6 // Check if gh CLI is installed
7 let version = client.check_installation()?;
8 println!("✓ GitHub CLI: {}", version.trim());
9
10 // List repositories
11 let repos = client.repo().list().limit(5).execute()?;
12 println!("{}", repos);
13
14 Ok(())
15}
Sourcepub fn repo(&self) -> RepoCommands
pub fn repo(&self) -> RepoCommands
Access repository commands
Examples found in repository?
examples/basic_usage.rs (line 11)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5
6 // Check if gh CLI is installed
7 let version = client.check_installation()?;
8 println!("✓ GitHub CLI: {}", version.trim());
9
10 // List repositories
11 let repos = client.repo().list().limit(5).execute()?;
12 println!("{}", repos);
13
14 Ok(())
15}
More examples
examples/repo.rs (line 7)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5 println!("Creating a new repository:");
6 match client
7 .repo()
8 .create("gh-cli-rs")
9 .description("A wrapper for GitHub CLI in Rust")
10 .public()
11 .with_readme()
12 .execute()
13 {
14 Ok(result) => println!("✓ Repository created: {}", result),
15 Err(e) => eprintln!("✗ Error: {}", e),
16 }
17
18 Ok(())
19}
Sourcepub fn pr(&self) -> PrCommands
pub fn pr(&self) -> PrCommands
Access pull request commands
Examples found in repository?
examples/pr.rs (line 8)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let client = GhClient::new();
5
6 println!("Creating a pull request...");
7 match client
8 .pr()
9 .create()
10 .title("test PR created by gh_cli_rs")
11 .body("This PR adds a new feature\n\n## Changes\n- Added feature X\n- Fixed bug Y")
12 // the branches must exist in remote repo for the command to work
13 .base("main")
14 .head("feature-branch")
15 .draft()
16 .execute()
17 {
18 Ok(result) => println!("✓ PR created: {}", result),
19 Err(e) => eprintln!("✗ Error: {}", e),
20 }
21
22 println!("\n🔍 Viewing PR #1:");
23 match client.pr().view(1).execute() {
24 Ok(pr) => println!("{}", pr),
25 Err(e) => eprintln!("✗ Error: {}", e),
26 }
27
28 Ok(())
29}
Sourcepub fn issue(&self) -> IssueCommands
pub fn issue(&self) -> IssueCommands
Access issue commands
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GhClient
impl RefUnwindSafe for GhClient
impl Send for GhClient
impl Sync for GhClient
impl Unpin for GhClient
impl UnwindSafe for GhClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more