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): pretty-print cargo loco routes #1073

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

AngelOnFira
Copy link
Contributor

@AngelOnFira AngelOnFira commented Dec 11, 2024

This add cleaner formatting to the cargo loco routes command.

image

@kaplanelad
Copy link
Contributor

Thank you, @AngelOnFira, for this PR!

We aim to minimize the number of external crates to reduce the binary size and compilation time.

If you can think of an alternative implementation that doesn’t rely on an external crate, that would be fantastic. Looking forward to your thoughts!

@AngelOnFira
Copy link
Contributor Author

Thanks for the quick reply! I mainly wanted to just give this a test first with the dependency, but I can definitely slim it down to not use anything external. I'll ping you once I get that in order! :)

@AngelOnFira
Copy link
Contributor Author

Here is a simple improvement:

METHOD URI
------ ---
GET    /_health
GET    /_ping
POST   /auth/forgot
POST   /auth/login
POST   /auth/register
POST   /auth/reset
POST   /auth/verify
GET    /cache
GET    /cache/get_or_insert
POST   /cache/insert
GET    /mylayer/admin
GET    /mylayer/echo
GET    /mylayer/user
GET    /mysession
GET    /notes
POST   /notes
GET    /notes/:id
DELETE /notes/:id
POST   /notes/:id
GET    /response/album
GET    /response/empty
GET    /response/empty_json
GET    /response/etag
GET    /response/html
GET    /response/json
GET    /response/redirect
GET    /response/render_with_status_code
GET    /response/set_cookie
GET    /response/text
POST   /upload/file
POST   /user/convert/admin
POST   /user/convert/user
GET    /user/current
GET    /user/current_api_key
GET    /view-engine/hello
GET    /view-engine/home
GET    /view-engine/simple

But I'm curious if a view like this might be a bit more natural to read:

/_health
  ├─ GET    
/_ping
  ├─ GET    
/auth
  ├─ POST   /forgot
  ├─ POST   /login
  ├─ POST   /register
  ├─ POST   /reset
  ├─ POST   /verify
/cache
  ├─ GET    
  ├─ GET    /get_or_insert
  ├─ POST   /insert
/mylayer
  ├─ GET    /admin
  ├─ GET    /echo
  ├─ GET    /user
/mysession
  ├─ GET    
/notes
  ├─ GET    
  ├─ POST   
  ├─ GET    /:id
  ├─ DELETE /:id
  ├─ POST   /:id
/response
  ├─ GET    /album
  ├─ GET    /empty
  ├─ GET    /empty_json
  ├─ GET    /etag
  ├─ GET    /html
  ├─ GET    /json
  ├─ GET    /redirect
  ├─ GET    /render_with_status_code
  ├─ GET    /set_cookie
  ├─ GET    /text
/upload
  ├─ POST   /file
/user
  ├─ POST   /convert/admin
  ├─ POST   /convert/user
  ├─ GET    /current
  ├─ GET    /current_api_key
/view-engine
  ├─ GET    /hello
  ├─ GET    /home
  ├─ GET    /simple

I'm going to do an iteration on that to make it a bit more clear, and maybe add some colour.

@AngelOnFira
Copy link
Contributor Author

Alright, I think I'm happy with this version

image

I think ordering could be discussed if it's not the best, since seeing GET, POST, GET, POST, DELETE might seem out of order, but it's due to it being the same endpoint used by multiple request types. I tried to separate that visually as well as I could.

image

@AngelOnFira
Copy link
Contributor Author

This should be ready now @kaplanelad! 🦀

@jondot
Copy link
Contributor

jondot commented Dec 12, 2024

@AngelOnFira this is beautiful, thanks!

@jondot jondot added this to the 0.14.0 milestone Dec 12, 2024
@kaplanelad
Copy link
Contributor

Thanks, @AngelOnFira, it looks much better! The event from the table is also great! :)

Could you please take a look at my comment and also address the CI issue?

By the way, we have a few more commands (beyond prints) that could benefit from a design update:

  • Scheduler: cargo loco scheduler --list
  • Tasks: cargo loco task
    For testing, head over to examples/demo and run the following command.

We’d really appreciate it if you could open another PR (no need in this PR) to apply your magic to these as well!

@AngelOnFira AngelOnFira changed the title Add prettytable formatting to cargo loco routes command feat(cli): pretty-print cargo loco routes Dec 12, 2024
@AngelOnFira
Copy link
Contributor Author

Thanks for the feedback!

Could you please take a look at my comment and also address the CI issue?

CI should be resolved (but I think I need a maintainer to allow it to run again). I'm not sure I saw a separate comment, I might have missed it somewhere. Did you mean to point something else out?

By the way, we have a few more commands (beyond prints) that could benefit from a design update

Awesome, thanks for the list! I've mostly used cargo loco routes myself, so I wasn't sure what else could use the uplift. I'll get those worked on soon!

@kaplanelad
Copy link
Contributor

@AngelOnFira
replace this color costs:

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
const GREEN: &str = "\x1b[32m";
const BLUE: &str = "\x1b[34m";
const YELLOW: &str = "\x1b[33m";
const MAGENTA: &str = "\x1b[35m";
const RED: &str = "\x1b[31m";

and use colored this is exists in cargo.toml

Thanks

@AngelOnFira
Copy link
Contributor Author

Ah yes, that makes a lot of sense. That should be fixed now! 🙌🏻

@AngelOnFira
Copy link
Contributor Author

I'll get CI working now

@AngelOnFira AngelOnFira force-pushed the add-prettytable branch 3 times, most recently from 45f6a99 to 392ace3 Compare December 12, 2024 15:22
@AngelOnFira
Copy link
Contributor Author

I was testing CI locally on my fork, and it looks like everything should pass now 🎉 I was having some issues with Mac, and temp directories, so I'll upstream some test fixes in another PR hopefully.

@jondot
Copy link
Contributor

jondot commented Dec 13, 2024

beautiful! merging!

@jondot jondot merged commit a4ca2e9 into loco-rs:master Dec 13, 2024
9 checks passed
@AngelOnFira AngelOnFira deleted the add-prettytable branch December 23, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants