Skip to content

Commit 4d203d2

Browse files
authored
Change ownerships to groups and some more (#24)
1 parent e89a112 commit 4d203d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+712
-263
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ It will create an empty config file
3737

3838
4. Work with teams
3939

40-
`teams` commands takes team names as arguments, so if you want to modify not default team pass an argumanet with a team name
4140
```
4241
$ gum teams help
4342
$ gum teams add-project -u PROJECT_ID # will add a project to the default team

TODO.md

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
# MVP
22
What needs to be done before the tool can actually be used.
3-
- [X] Implement all required gitlab API
4-
- APIs
5-
- Add members
6-
- Delete members
7-
- Update members
8-
- On adding handle error User Already Exists
9-
- On removing handle error User Not Found
10-
- Add corresponding output to error handling (Already Added, Not Found)
11-
12-
- [ ] Get rid of billions of loops and start using HashMaps
133
- [ ] Add tests
14-
- [X] Create a Dockerfile and GitHub Actions for tests and releases
15-
- [ ] Refactor whole arguments module. Maybe rewrite it to methods or something
164
- [ ] Refactor error handling
17-
- [ ] Write good documentation in README.md
185

196
# Nice to have
207
- [ ] Add a `describe` command foreach config entity
@@ -32,8 +19,6 @@ What needs to be done before the tool can actually be used.
3219
```
3320

3421
- [ ] Async actions
35-
- [ ] Get rid of state file
36-
- [X] Use spinners for output
3722
- [ ] Add auto suggestions for every command
3823
- [ ] Start versioning the config file and add possibility to migrate from to a newer version. And add kinda annotation to let gum know it's a gum-config. Something like that
3924
```
@@ -63,8 +48,8 @@ What needs to be done before the tool can actually be used.
6348
```
6449
And remove each user, which is being updated anyhow, from groups provided via head_groups (remove from groups, sub groups and projects)
6550

66-
- [ ] Remove extra fields from state. State should only contain IDs and access_level
67-
- [ ] Auto check for updates
51+
- [X] Remove extra fields from state. State should only contain IDs and access_level
52+
- [X] Auto check for updates
6853
- [ ] Add feature for inviting users, if it's possible.
6954
When user is invited, he won't have an id until he confirms invitation. But after he confirms, he will be added to projects where he's been invited. So I think it should look like that:
7055
- New object is added to config
@@ -75,7 +60,7 @@ And remove each user, which is being updated anyhow, from groups provided via he
7560
teams: []
7661
groups: []
7762
```
78-
- On each sync this invites should be checked for confirmation (if there so no such possibility, the whole invite ting seems impossible)
63+
- On each sync this invites should be checked for confirmation (if there so no such possibility, the whole invite thing seems impossible)h
7964
- If it's confirmed, the user should be automatically added to users and to state
8065
- [ ] Add patterns for checking users emails and usernames
8166
# Maybe nice to have

example/gum-config-v1.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
meta:
2+
version: v1
3+
config:
4+
teams:
5+
name: default
6+
projects: []
7+
users: []
8+
state:

example/gum-config-v2.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# How I think config should look like
2+
meta:
3+
version: v2
4+
groups:
5+
- id: group_id
6+
name: group_name
7+
- id: group_id
8+
name: group_name
9+
patterns:
10+
users:
11+
name: regexp
12+
username: regexp
13+
email: regexp
14+
projects:
15+
name: regexp
16+
config:
17+
teams:
18+
name: default
19+
projects: []
20+
groups: []
21+
users:
22+
- user:
23+
id: user_id
24+
name: name
25+
username: username
26+
email: email
27+
projects:
28+
- data:
29+
id: user_id
30+
name: project_name
31+
url: project_url
32+
access: Developer
33+
groups:
34+
- data:
35+
id: user_id
36+
name: group_name
37+
url: group_url
38+
access: Developer
39+
teams:
40+
- team_1
41+
- team_2
42+
- team_3
43+
state:
44+
last_sync:
45+
- user_info:
46+
id: user_id
47+
name: name
48+
username: username
49+
email: email
50+
- date: DATE
51+
data: ~

src/args.rs

+4-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pub(crate) mod file_name;
44
pub(crate) mod gitlab_token;
55
pub(crate) mod gitlab_url;
66
pub(crate) mod group_id;
7+
pub(crate) mod group_list;
8+
pub(crate) mod large_out;
9+
pub(crate) mod no_confirm;
710
pub(crate) mod project_id;
811
pub(crate) mod state_destination;
912
pub(crate) mod state_source;
@@ -14,43 +17,8 @@ pub(crate) mod write_state;
1417
use clap::{Arg, ArgMatches};
1518
use std::io::Result;
1619

17-
pub(crate) trait Args<'a> {
20+
pub(crate) trait Args {
1821
type ArgType;
1922
fn add() -> Arg<'static>;
2023
fn parse<'b>(sub_matches: &'b ArgMatches) -> Result<Self::ArgType>;
2124
}
22-
23-
pub(crate) mod no_confirm {
24-
use clap::{Arg, ArgMatches};
25-
26-
use super::Args;
27-
28-
static ARG: &str = "no-confirm";
29-
pub(crate) struct ArgNoConfirm {
30-
value: bool,
31-
}
32-
33-
impl ArgNoConfirm {
34-
pub(crate) fn value(&self) -> bool {
35-
self.value
36-
}
37-
}
38-
39-
impl Args<'_> for ArgNoConfirm {
40-
type ArgType = ArgNoConfirm;
41-
42-
fn add() -> Arg<'static> {
43-
Arg::new(ARG)
44-
.long(ARG)
45-
.short('y')
46-
.takes_value(false)
47-
.help("Use if the user shouldn't be prompted to confirm an update")
48-
}
49-
50-
fn parse<'b>(sub_matches: &'b ArgMatches) -> std::io::Result<Self::ArgType> {
51-
Ok(ArgNoConfirm {
52-
value: sub_matches.is_present(ARG),
53-
})
54-
}
55-
}
56-
}

src/args/access_level.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Args;
2-
use crate::{output::OutMessage, types::v1::access_level::AccessLevel};
2+
use crate::{output::out_message::OutMessage, types::v1::access_level::AccessLevel};
33
use clap::{Arg, ArgMatches};
44
use std::{
55
io::{Error, Result},
@@ -18,7 +18,7 @@ impl ArgAccess {
1818
}
1919
}
2020

21-
impl Args<'_> for ArgAccess {
21+
impl Args for ArgAccess {
2222
type ArgType = ArgAccess;
2323

2424
fn add() -> Arg<'static> {
@@ -46,4 +46,4 @@ impl Args<'_> for ArgAccess {
4646
};
4747
})
4848
}
49-
}
49+
}

src/args/dry_run.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::{Arg, ArgMatches};
22

33
use super::Args;
44

5-
static ARG_DRY_RUN: &str = "dry-run";
5+
static ARG: &str = "dry-run";
66
pub(crate) struct ArgDryRun {
77
value: bool,
88
}
@@ -13,20 +13,20 @@ impl ArgDryRun {
1313
}
1414
}
1515

16-
impl Args<'_> for ArgDryRun {
16+
impl Args for ArgDryRun {
1717
type ArgType = ArgDryRun;
1818

1919
fn add() -> Arg<'static> {
20-
Arg::new(ARG_DRY_RUN)
21-
.long("dry-run")
20+
Arg::new(ARG)
21+
.long(ARG)
2222
.short('d')
2323
.takes_value(false)
2424
.help("Use if you wanna see what's gonna happen without actually applying a new configuration")
2525
}
2626

2727
fn parse<'b>(sub_matches: &'b ArgMatches) -> std::io::Result<Self::ArgType> {
2828
Ok(ArgDryRun {
29-
value: sub_matches.is_present(ARG_DRY_RUN),
29+
value: sub_matches.is_present(ARG),
3030
})
3131
}
3232
}

src/args/file_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Args;
2-
use crate::output::OutMessage;
2+
use crate::output::out_message::OutMessage;
33
use clap::{Arg, ArgMatches};
44
use std::io::{Error, Result};
55

@@ -15,7 +15,7 @@ impl ArgFileName {
1515
}
1616
}
1717

18-
impl Args<'_> for ArgFileName {
18+
impl Args for ArgFileName {
1919
type ArgType = ArgFileName;
2020

2121
fn add() -> Arg<'static> {

src/args/gitlab_token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Args;
2-
use crate::output::OutMessage;
2+
use crate::output::out_message::OutMessage;
33
use clap::{Arg, ArgMatches};
44
use std::io::{Error, Result};
55

@@ -15,7 +15,7 @@ impl ArgGitlabToken {
1515
}
1616
}
1717

18-
impl Args<'_> for ArgGitlabToken {
18+
impl Args for ArgGitlabToken {
1919
type ArgType = ArgGitlabToken;
2020

2121
fn add() -> Arg<'static> {

src/args/gitlab_url.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Args;
2-
use crate::output::OutMessage;
2+
use crate::output::out_message::OutMessage;
33
use clap::{Arg, ArgMatches};
44
use std::io::{Error, Result};
55

@@ -15,7 +15,7 @@ impl ArgGitlabUrl {
1515
}
1616
}
1717

18-
impl Args<'_> for ArgGitlabUrl {
18+
impl Args for ArgGitlabUrl {
1919
type ArgType = ArgGitlabUrl;
2020

2121
fn add() -> Arg<'static> {

src/args/group_id.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl ArgGroupId {
1414
}
1515
}
1616

17-
impl Args<'_> for ArgGroupId {
17+
impl Args for ArgGroupId {
1818
type ArgType = ArgGroupId;
1919

2020
fn add() -> Arg<'static> {

src/args/group_list.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use super::Args;
2+
use clap::{Arg, ArgMatches};
3+
use std::io::{Error, ErrorKind, Result};
4+
5+
static ARG: &str = "groups";
6+
7+
pub(crate) struct ArgGroupList {
8+
value: Vec<u64>,
9+
}
10+
11+
impl ArgGroupList {
12+
/// Get a reference to the arg group list's value.
13+
14+
/// Get a reference to the arg group list's value.
15+
pub(crate) fn value(&self) -> &[u64] {
16+
self.value.as_ref()
17+
}
18+
}
19+
20+
impl Args for ArgGroupList {
21+
type ArgType = ArgGroupList;
22+
23+
fn add() -> Arg<'static> {
24+
Arg::new(ARG)
25+
.short('g')
26+
.long(ARG)
27+
.takes_value(true)
28+
.value_name("GROUP_IDS")
29+
.help("Provide a list of groups to create a snapshot on initializing")
30+
.global(true)
31+
.multiple_values(true)
32+
}
33+
34+
fn parse<'a>(sub_matches: &'a ArgMatches) -> Result<Self> {
35+
let value = match sub_matches.values_of(ARG) {
36+
Some(v) => v.map(|f| f.parse::<u64>().unwrap()).collect(),
37+
None => {
38+
return Err(Error::new(
39+
ErrorKind::InvalidInput,
40+
"You have to provide values for using group-list args",
41+
))
42+
}
43+
};
44+
45+
Ok(ArgGroupList { value })
46+
}
47+
}

src/args/large_out.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use clap::{Arg, ArgMatches};
2+
3+
use super::Args;
4+
5+
static ARG: &str = "large";
6+
pub(crate) struct ArgLargeOut {
7+
value: bool,
8+
}
9+
10+
impl ArgLargeOut {
11+
pub(crate) fn value(&self) -> bool {
12+
self.value
13+
}
14+
}
15+
16+
impl Args for ArgLargeOut {
17+
type ArgType = ArgLargeOut;
18+
19+
fn add() -> Arg<'static> {
20+
Arg::new(ARG)
21+
.long(ARG)
22+
.short('l')
23+
.takes_value(false)
24+
.help("Display a lot of data")
25+
}
26+
27+
fn parse<'b>(sub_matches: &'b ArgMatches) -> std::io::Result<Self::ArgType> {
28+
Ok(ArgLargeOut {
29+
value: sub_matches.is_present(ARG),
30+
})
31+
}
32+
}

0 commit comments

Comments
 (0)