Task list view: adjust text alignment
In Loco, there is an option to view all available tasks by executing the command: cargo loco task. The purpose of this command is to display a list of tasks registered with Loco that can be executed. The output of this command includes the task ID and a brief description of each task.
❯ cargo loco task
seed_data [Task for seeding data]
When adding a new task, the output appears as follows:
❯ cargo loco task
seed_data [Task for seeding data]
sync [Sync data]
we need to make sure that the description view starts in the same column:
expected:
❯ cargo loco task
seed_data [Task for seeding data]
sync [Sync data]
- loco/examples/demo doesn't show 2nd task lineup correctly, Is this still a problem in 0.2.5 ?
Try maybe a smaller task name like sync.
- Issue confirmed.
me@rocky9t01a myapp2]$ myapp2-cli generate task sync
me@rocky9t01a myapp2]$ cargo install --path . --force
[me@rocky9t01a myapp2]$ myapp2-cli task
seed_data [Task for seeding data]
sync [Task generator]
[me@rocky9t01a myapp2]$
-
See TaskInfo in screen shot below for Tasks/seed.rs and Tasks/sync.rs
-
I guess we need to use std::fmt to do center align. but I can't figure out how to do that yet ?
@tjyang you are more than welcome to up a PR with this fix
I really want to attempt this one. Let me look into it.
@tjyang you are more than welcome to up a PR with this fix
I don't know how? I am not a developer ;-< @mikosco4real go for this challenge.
- TaskInfo is a structure with two string members.
TaskInfo {
name: "seed_data".to_string(),
detail: "Task for seeding data".to_string(),
}
- or here loco/src/task.rs
[me@rocky9t01a src]$ pwd;grep TaskInfo task.rs
/home/me/github/learnrust/loco/src
pub struct TaskInfo {
fn task(&self) -> TaskInfo;
pub fn list(&self) -> Vec<TaskInfo> {
[me@rocky9t01a src]$
@kaplanelad , I assume that for https://github.com/loco-rs/loco/issues/228 there are likely two ways to implement it. Since I am new to Rust I will appreciate some directions here.
-
I can implement Display trait for TaskInfo (loco/src/task.rs ln:13) and then update boot.rs ( src/boot.rs ln:107) to simply print item.
-
I can reformat the printing directly on boot.rs line 107 to adapt to the longest task.name in the task.list() returned.
Let me know if there are other considerations I missed. Thank you.
Hey @mikosco4real thank you for taking this issue
Here you can find where we are printing the results.
i think we can remove the /t/t and replace it with something like {0: <10}
Thanks @kaplanelad
@kaplanelad What is the easiest way to test this change in my local? I mean I have created the tasks and now when I say:
cargo loco task
it lists the misaligned task. I want to run it with my local loco-rs fork. What is the easiest way to do this?
@mikosco4real To test the CLI, we using trycmd in our project, and you can find an example here.
For tesing, let's create a new task in the demo example named "foo" (or any other short name). You can add this task here. For more details on registering tasks, refer to the documentation.
After adding your task, update the snapshot using the following command:
TRYCMD=overwrite LOCO_CI_MODE=true cargo insta test --review
Make sure you have insta installed for the snapshot. if you don't have, install insta with the following command cargo install insta
I recommend registering the task, disabling your changes by commenting your change, and running the snapshot. You should see the list task output is not aligned. Then, bring back your code, update the snapshot again, and confirm that the results align with expectations.
@kaplanelad, I registered a new task called foo and then I tried running the command
TRYCMD=overwrite LOCO_CI_MODE=true cargo insta test --review
It just runs the tests without printing out anything like the added task. Should I also create a test and record a snapshot to be able to use this feature?
@mikosco4real, you don't need to create a test for the dummy new task
#237