loco icon indicating copy to clipboard operation
loco copied to clipboard

Task list view: adjust text alignment

Open kaplanelad opened this issue 2 years ago • 14 comments

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]

kaplanelad avatar Dec 24 '23 07:12 kaplanelad

  • loco/examples/demo doesn't show 2nd task lineup correctly, Is this still a problem in 0.2.5 ? image

tjyang avatar Dec 24 '23 10:12 tjyang

Try maybe a smaller task name like sync.

kaplanelad avatar Dec 24 '23 11:12 kaplanelad

  • 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]$

tjyang avatar Dec 25 '23 03:12 tjyang

  • See TaskInfo in screen shot below for Tasks/seed.rs and Tasks/sync.rs image

  • I guess we need to use std::fmt to do center align. but I can't figure out how to do that yet ? image

tjyang avatar Dec 25 '23 07:12 tjyang

@tjyang you are more than welcome to up a PR with this fix

kaplanelad avatar Dec 25 '23 07:12 kaplanelad

I really want to attempt this one. Let me look into it.

mikosco4real avatar Dec 25 '23 07:12 mikosco4real

@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]$

tjyang avatar Dec 25 '23 07:12 tjyang

@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.

  1. 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.

  2. 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.

mikosco4real avatar Dec 25 '23 08:12 mikosco4real

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}

kaplanelad avatar Dec 25 '23 11:12 kaplanelad

Thanks @kaplanelad

mikosco4real avatar Dec 25 '23 13:12 mikosco4real

@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 avatar Dec 25 '23 20:12 mikosco4real

@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 avatar Dec 25 '23 21:12 kaplanelad

@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 avatar Dec 26 '23 01:12 mikosco4real

@mikosco4real, you don't need to create a test for the dummy new task

kaplanelad avatar Dec 26 '23 05:12 kaplanelad

#237

kaplanelad avatar Dec 31 '23 08:12 kaplanelad