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

feat(cli): Improve the list command with options, and then some #599

Merged
merged 2 commits into from
Jan 17, 2021

Conversation

AbdouSeck
Copy link
Contributor

@AbdouSeck AbdouSeck commented Dec 13, 2020

The PR is two-fold:

  1. rustlings list should now display more than just the exercise names. Information such as file paths and exercises statuses should be displayed. The --paths option limits the displayed fields to only the path names; while the --names option limits the displayed fields to only exercise names. You can also control which exercises are displayed, by using the --filter option, or the --solved or --unsolved flags.

Sample invocations:

# Display exercises that deal with traits, or enums, or structs.
rustlings list --filter "trait,enum,struct"

# Sample output:
# Name             	Path                                          	Status
# structs1         	exercises/structs/structs1.rs                 	Pending
# structs2         	exercises/structs/structs2.rs                 	Pending
# structs3         	exercises/structs/structs3.rs                 	Pending
# enums1           	exercises/enums/enums1.rs                     	Pending
# enums2           	exercises/enums/enums2.rs                     	Pending
# enums3           	exercises/enums/enums3.rs                     	Pending
# traits1          	exercises/traits/traits1.rs                   	Pending
# traits2          	exercises/traits/traits2.rs                   	Pending

# Display only exercises pending to be solved
rustlings list --unsolved

# Sample output:
# Name             	Path                                          	Status
# structs2         	exercises/structs/structs2.rs                 	Pending
# structs3         	exercises/structs/structs3.rs                 	Pending
# enums1           	exercises/enums/enums1.rs                     	Pending
# enums2           	exercises/enums/enums2.rs                     	Pending
# enums3           	exercises/enums/enums3.rs                     	Pending
# modules1         	exercises/modules/modules1.rs                 	Pending
# modules2         	exercises/modules/modules2.rs                 	Pending
# collections1     	exercises/collections/vec1.rs                 	Pending
# collections2     	exercises/collections/vec2.rs                 	Pending
# collections3     	exercises/collections/hashmap1.rs             	Pending
# collections4     	exercises/collections/hashmap2.rs             	Pending

This portion should also close #281.

Some shell utility use cases:

  • Fetching pending exercise file paths with the keyword "conversion" to pass to my editor:
vim $(rustlings list --filter "conversion" --paths --unsolved)
  • Fetching exercise names with keyword "conversion" to pass to rustlings run:
for exercise in $(rustlings list --filter "conversion" --names)
do
    rustlings run ${exercise}
done
  1. The PR should also fix Unexpected completion #465, and will likely fix as_ref_mut not ran #585, as well. The bug mentioned in those issues has to do with the way the watch command handler fetches the pending exercises.
    Going forward, the least recently updated exercises along with all the other exercises in a pending state are fetched.

@fmoko @jrvidal if you've got some time, I'd love an eye on this. If there is anyone else with some experience on (or interest in) the CLI component, please feel free to let me know what you think.

Thanks,
Abdou

Copy link
Contributor

@jrvidal jrvidal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, but this looks good @AbdouSeck 🚀

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@AbdouSeck AbdouSeck force-pushed the improve-list-command branch 3 times, most recently from 4165bd3 to 9d1676f Compare December 16, 2020 00:16
@AbdouSeck AbdouSeck force-pushed the improve-list-command branch 2 times, most recently from 292b45c to e6dc81b Compare December 31, 2020 23:49
@AbdouSeck AbdouSeck force-pushed the improve-list-command branch 2 times, most recently from a229784 to d1f25b0 Compare January 8, 2021 13:20
1.
`rustlings list` should now display more than just the exercise names.
Information such as file paths and exercises statuses should be displayed.
The `--paths` option limits the displayed fields to only the path names; while the `--names`
option limits the displayed fields to only exercise names.
You can also control which exercises are displayed, by using the `--filter` option, or
the `--solved` or `--unsolved` flags.

Some use cases:
- Fetching pending exercise files with the keyword "conversion" to pass to my editor:
```sh
vim $(rustlings list --filter "conversion" --paths --unsolved)
```

- Fetching exercise names with keyword "conversion" to pass to `rustlings run`:
```sh
for exercise in $(rustlings list --filter "conversion" --names)
do
    rustlings run ${exercise}
done
```

2.
This should also fix rust-lang#465, and will likely fix rust-lang#585, as well.
That bug mentioned in those issues has to do with the way the `watch` command handler fetches the pending exercises.
Going forward, the least recently updated exercises along with all the other exercises in a pending state are fetched.
@AbdouSeck AbdouSeck force-pushed the improve-list-command branch from d1f25b0 to 8bbe4ff Compare January 8, 2021 18:21
@shadows-withal shadows-withal merged commit e8d1baa into rust-lang:main Jan 17, 2021
ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
feat(cli): Improve the list command with options, and then some
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
feat(cli): Improve the list command with options, and then some
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants