Julien-cpsn / ATAC

A simple API client (postman like) in your terminal
https://atac.julien-cpsn.com/
MIT License
1.36k stars 66 forks source link

Feature Request: use default `directory` if not specified #68

Open namespaceYcZ opened 2 months ago

namespaceYcZ commented 2 months ago

Now ATAC (version 0.15.1) must be given a working directory on startup. image

IMHO, a tui application can use the default directory specified by the OS, i.e: OS config directory cache directory
Linux /home/alice/.config/barapp /home/alice/.cache/barapp
Windows C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config C:\Users\Alice\AppData\Local\Foo Corp\Bar App\cache
MacOS /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App /Users/Alice/Library/Caches/com.Foo-Corp.Bar-App

(Suppose the user name is Alice, the organization name is Foo Corp and the application name is Bar App).

All this can be easily handled by the directory crate:

[dependencies]
directories = "5"
// these are just examples, there must be some other much more better options
// and if you want the `ORGANIZATION` be present on Linux, some thing like `#[cfg(target_os = "linux")]` can be used
pub const APP_NAME: &str = "ATAC";
pub const QUALIFIER: &str = "fr";
pub const ORGANIZATION: &str = "Julien";

let project_dir = directories::ProjectDirs::from(QUALIFIER, ORGANIZATION, APP_NAME).unwrap();
let config_dir = project_dir.config_dir();
let cache_dir = project_dir.cache_dir();
let mut log_dir = cache_dir.to_owned();
log_dir.push("logs");
Julien-cpsn commented 2 months ago

Hello @namespaceYcZ

Yes this a thing that is planned for later, a dedicated directory inside the system would be great. It is not implemeted yet because I don't know how make it cross-platform. But your solution seems good to me, I'll look into it further.

Have you tried using the ATAC_MAIN_DIR env variable before the features comes out?

Have a great day

PS: do you have more knowledge on how to implement those things? I have some questions

namespaceYcZ commented 2 months ago

Hello @namespaceYcZ

Yes this a thing that is planned for later, a dedicated directory inside the system would be great. It is not implemeted yet because I don't know how make it cross-platform. But your solution seems good to me, I'll look into it further.

Have you tried using the ATAC_MAIN_DIR env variable before the features comes out?

Have a great day

PS: do you have more knowledge on how to implement those things? I have some questions

I tried. Both these two ways work fine for me: image

Thank you for your nice work! I have been longing for a tui Postman-like application for a long time.

What kind of knowledge do you need? I'm very glad to help but I lack experience and necessary knowledge. I saw some links on the document page of the directories crate which might help you.

Julien-cpsn commented 2 months ago

What kind of knowledge do you need? I'm very glad to help but I lack experience and necessary knowledge. I saw some links on the document page of the directories crate which might help you.

I do not understand how the directory gets created, does I need to always try to create the directory when using the app ? Or does it needs something specific when installing?

Will it work with the ATAC_MAIN_DIR variable or do I have to change the way it works?

Thanks in advance

namespaceYcZ commented 2 months ago

What kind of knowledge do you need? I'm very glad to help but I lack experience and necessary knowledge. I saw some links on the document page of the directories crate which might help you.

I do not understand how the directory gets created, does I need to always try to create the directory when using the app ? Or does it needs something specific when installing?

Will it work with the ATAC_MAIN_DIR variable or do I have to change the way it works?

Thanks in advance

image image

I think the directories crate doesn't automatically create the project directory for us. So I suggest that ATAC create it if the directory argument was not provided, the ATAC_MAIN_DIR env variable was not provided and the project directory was not found.

I draw a flow chart to make it clear: 未命名文件

ccoVeille commented 3 weeks ago

IMHO, a tui application can use the default directory specified by the OS, i.e:\n\nOS\tconfig directory\tcache directory\nLinux\t/home/alice/.config/barapp\t/home/alice/.cache/barapp\nWindows\tC:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config\tC:\Users\Alice\AppData\Local\Foo Corp\Bar App\cache\nMacOS\t/Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App\t/Users/Alice/Library/Caches/com.Foo-Corp.Bar-App\n(Suppose the user name is Alice, the organization name is Foo Corp and the application name is Bar App).\n\nAll this can be easily handled by the directory crate:\n\n[dependencies]\ndirectories = \"5\"\n// these are just examples, there must be some other much more better options\n// and if you want the ORGANIZATION be present on Linux, some thing like #[cfg(target_os = \"linux\")] can be used\npub const APP_NAME: &str = \"ATAC\";\npub const QUALIFIER: &str = \"fr\";\npub const ORGANIZATION: &str = \"Julien\";\n\nlet project_dir = directories::ProjectDirs::from(QUALIFIER, ORGANIZATION, APP_NAME).unwrap();\nlet config_dir = project_dir.config_dir();\nlet cache_dir = project_dir.cache_dir();\nlet mut log_dir = cache_dir.to_owned();\nlog_dir.push(\"logs\");

Please also consider that in addition of that, people might expect to respect XDG_CONFIG_HOME and XDG_DATA_HOME

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Does this crate respect that?

namespaceYcZ commented 2 weeks ago

IMHO, a tui application can use the default directory specified by the OS, i.e:\n\nOS\tconfig directory\tcache directory\nLinux\t/home/alice/.config/barapp\t/home/alice/.cache/barapp\nWindows\tC:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config\tC:\Users\Alice\AppData\Local\Foo Corp\Bar App\cache\nMacOS\t/Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App\t/Users/Alice/Library/Caches/com.Foo-Corp.Bar-App\n(Suppose the user name is Alice, the organization name is Foo Corp and the application name is Bar App).\n\nAll this can be easily handled by the directory crate:\n\n[dependencies]\ndirectories = "5"\n// these are just examples, there must be some other much more better options\n// and if you want the ORGANIZATION be present on Linux, some thing like #[cfg(target_os = \"linux\")] can be used\npub const APP_NAME: &str = "ATAC";\npub const QUALIFIER: &str = "fr";\npub const ORGANIZATION: &str = "Julien";\n\nlet project_dir = directories::ProjectDirs::from(QUALIFIER, ORGANIZATION, APP_NAME).unwrap();\nlet config_dir = project_dir.config_dir();\nlet cache_dir = project_dir.cache_dir();\nlet mut log_dir = cache_dir.to_owned();\nlog_dir.push("logs");

Please also consider that in addition of that, people might expect to respect XDG_CONFIG_HOME and XDG_DATA_HOME

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Does this crate respect that?

I'm not quite sure, maybe it does according to its comment: image image