Skip to content

Commit

Permalink
Add no sections to config
Browse files Browse the repository at this point in the history
  • Loading branch information
alanvardy committed Sep 19, 2023
1 parent 45dcb41 commit fa6e1b8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add `nosection` flag to `task create`
- Add `No section` option to section selection
- Add `no_sections` config option

## 2023-09-04 v0.5.1

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ Location of the `tod` configuration file

If true, the datetime selection in `project schedule` will go straight to natural language input.

#### no_sections

```
type: nullable boolean
default: null
possible values: null, true, or false
```

If true will not prompt for a section whenever possible

#### spinners

```
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct Config {
pub mock_select: Option<usize>,
/// Whether spinners are enabled
pub spinners: Option<bool>,
/// Don't ask for sections
pub no_sections: Option<bool>,
/// Goes straight to natural language input in datetime selection
pub natural_language_only: Option<bool>,
}
Expand Down Expand Up @@ -139,6 +141,7 @@ impl Config {
timezone: None,
spinners: Some(true),
mock_url: None,
no_sections: None,
natural_language_only: None,
mock_string: None,
mock_select: None,
Expand Down Expand Up @@ -337,6 +340,7 @@ mod tests {
token: String::new(),
projects: Some(Vec::new()),
path: config.clone().unwrap().path,
no_sections: None,
next_id: None,
spinners: Some(true),
last_version_check: None,
Expand Down Expand Up @@ -364,6 +368,7 @@ mod tests {
projects: Some(Vec::new()),
path: config.clone().unwrap().path,
next_id: None,
no_sections: None,
spinners: Some(true),
last_version_check: None,
timezone: None,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn task_create(matches: &ArgMatches) -> Result<String, String> {
let project = fetch_project(matches, &config)?;
let description = fetch_description(matches);
let due = fetch_due(matches);
let section = if has_flag(matches, "nosection") {
let section = if has_flag(matches, "nosection") || config.no_sections.unwrap_or_default() {
None
} else {
let sections = todoist::sections_for_project(&config, &project)?;
Expand Down
2 changes: 1 addition & 1 deletion src/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ pub fn move_task_to_project(config: &Config, task: Task) -> Result<String, Strin

let sections = todoist::sections_for_project(config, &project)?;
let section_names: Vec<String> = sections.clone().into_iter().map(|x| x.name).collect();
if section_names.is_empty() {
if section_names.is_empty() || config.no_sections.unwrap_or_default() {
todoist::move_task_to_project(config, task, &project)
} else {
let section_name =
Expand Down
1 change: 1 addition & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod fixtures {
next_id: None,
timezone: Some(String::from("US/Pacific")),
last_version_check: None,
no_sections: None,
mock_url: None,
mock_string: None,
mock_select: None,
Expand Down

0 comments on commit fa6e1b8

Please sign in to comment.