Skip to content

Commit 1ef44b5

Browse files
committed
added following command
1 parent 3b6599f commit 1ef44b5

4 files changed

Lines changed: 85 additions & 15 deletions

File tree

.github/workflows/publish.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ jobs:
5252
run: |
5353
choco install zip
5454
cd target/${{ matrix.target }}/release
55-
zip gstats-0.1.0-${{ matrix.target }}.zip gstats.exe
55+
zip gstats-0.1.1-${{ matrix.target }}.zip gstats.exe
5656
cd ../../..
5757
5858
- name: Create tar.gz file on macOS
5959
if: ${{ matrix.os == 'macos-latest' }}
6060
run: |
6161
chmod +x target/${{ matrix.target }}/release/gstats
62-
tar -zcf target/${{ matrix.target }}/release/gstats-0.1.0-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release gstats
62+
tar -zcf target/${{ matrix.target }}/release/gstats-0.1.1-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release gstats
6363
chmod +x target/${{ matrix.target2 }}/release/gstats
64-
tar -zcf target/${{ matrix.target2 }}/release/gstats-0.1.0-${{ matrix.target2 }}.tar.gz -C target/${{ matrix.target2 }}/release gstats
64+
tar -zcf target/${{ matrix.target2 }}/release/gstats-0.1.1-${{ matrix.target2 }}.tar.gz -C target/${{ matrix.target2 }}/release gstats
6565
6666
- name: Upload release and assets to GitHub
6767
uses: svenstaro/upload-release-action@v2
6868
with:
6969
repo_token: ${{ secrets.GITHUB_TOKEN }}
70-
tag: "release-0.1.0-${{ github.run_number }}"
71-
release_name: gstats 0.1.0
70+
tag: "release-0.1.1-${{ github.run_number }}"
71+
release_name: gstats 0.1.1
7272
file_glob: true
73-
file: target/*/release/gstats-0.1.0-*.{zip,tar.gz}
73+
file: target/*/release/gstats-0.1.1-*.{zip,tar.gz}

src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pub mod all;
22
pub mod releases;
33
pub mod user;
4-
pub mod followers;
4+
pub mod relations;
Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
use crate::utils::{request, write_to_file};
22
use std::path::PathBuf;
33

4-
pub fn followers_command(user: String, total: bool, output: Option<PathBuf>, display: bool) {
5-
let url = format!("https://api.github.com/users/{}/followers", user);
4+
pub enum RelationType {
5+
Follower,
6+
Following,
7+
}
8+
9+
impl RelationType {
10+
pub fn to_text(&self) -> String {
11+
match self {
12+
RelationType::Follower => "Followers".to_string(),
13+
RelationType::Following => "Following".to_string(),
14+
}
15+
}
16+
}
17+
18+
pub fn relations_command(
19+
user: String,
20+
total: bool,
21+
output: Option<PathBuf>,
22+
display: bool,
23+
relation_type: RelationType,
24+
) {
25+
let url = format!(
26+
"https://api.github.com/users/{}/{}",
27+
user,
28+
relation_type.to_text().to_ascii_lowercase()
29+
);
630

731
let json = request(url).expect("Failed to request data");
832

@@ -19,11 +43,15 @@ pub fn followers_command(user: String, total: bool, output: Option<PathBuf>, dis
1943
println!();
2044
}
2145
if total {
22-
println!("Followers: {}", json.as_array().unwrap().len())
46+
println!(
47+
"{}: {}",
48+
relation_type.to_text(),
49+
json.as_array().unwrap().len()
50+
)
2351
}
2452
} else {
2553
let mut total_json = serde_json::Map::new();
26-
total_json.insert("followers".to_string(), json.clone());
54+
total_json.insert(relation_type.to_text().to_ascii_lowercase(), json.clone());
2755
if total {
2856
total_json.insert(
2957
"total".to_string(),
@@ -40,7 +68,7 @@ pub fn followers_command(user: String, total: bool, output: Option<PathBuf>, dis
4068
"total".to_string(),
4169
serde_json::Value::Number(serde_json::Number::from(json.as_array().unwrap().len())),
4270
);
43-
total_json.insert("followers".to_string(), json);
71+
total_json.insert(relation_type.to_text().to_ascii_lowercase(), json);
4472

4573
match output {
4674
Some(path) => {

src/main.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod utils;
44

55
use crate::cli::{Arg, Cli, Command};
66
use crate::commands::all::all_command;
7-
use crate::commands::followers::followers_command;
7+
use crate::commands::relations::{relations_command, RelationType};
88
use crate::commands::releases::releases_command;
99
use crate::commands::user::user_command;
1010
use crate::utils::{install, validate_and_convert_path, OS};
@@ -137,7 +137,39 @@ fn main() {
137137
.with_short('t')
138138
.with_long("total")
139139
.with_value_name("TOTAL")
140-
.with_help("Only gives the follower count"),
140+
.with_help("Gives the follower count"),
141+
)
142+
.with_arg(
143+
Arg::new()
144+
.with_name("output")
145+
.with_short('o')
146+
.with_long("output")
147+
.with_value_name("OUTPUT")
148+
.with_help("File path to save the json"),
149+
)
150+
.with_arg(
151+
Arg::new()
152+
.with_name("display")
153+
.with_short('d')
154+
.with_long("display")
155+
.with_help("Converts the json to an easier format (will remove some data)"),
156+
),
157+
Command::new("following", "Lists users the user is following")
158+
.with_arg(
159+
Arg::new()
160+
.with_name("user")
161+
.with_short('u')
162+
.with_long("user")
163+
.with_value_name("USER")
164+
.with_help("The user you want information on"),
165+
)
166+
.with_arg(
167+
Arg::new()
168+
.with_name("total")
169+
.with_short('t')
170+
.with_long("total")
171+
.with_value_name("TOTAL")
172+
.with_help("Gives the following count"),
141173
)
142174
.with_arg(
143175
Arg::new()
@@ -210,7 +242,17 @@ fn main() {
210242

211243
let output = output_to_path(output);
212244

213-
followers_command(user, total, output, display);
245+
relations_command(user, total, output, display, RelationType::Follower);
246+
}
247+
"following" => {
248+
let user = command.get_value_of("user").throw_if_none();
249+
let total = command.has("total");
250+
let output = command.get_value_of("output").to_option();
251+
let display = command.has("display");
252+
253+
let output = output_to_path(output);
254+
255+
relations_command(user, total, output, display, RelationType::Following);
214256
}
215257
"help" => cli.help(),
216258
_ => cli.help(),

0 commit comments

Comments
 (0)