-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor ark-cli
for Improved Code Organization and Readability
#67
Conversation
Benchmark for 23e3961Click to view benchmark
|
a294147
to
463750b
Compare
Benchmark for 49b25b8Click to view benchmark
|
ark-cli/src/commands/file/append.rs
Outdated
@@ -35,12 +41,13 @@ impl Append { | |||
translate_storage(&Some(self.root_dir.to_owned()), &self.storage) | |||
.ok_or(AppError::StorageNotFound(self.storage.to_owned()))?; | |||
|
|||
// FIXME: Why do we have `self.kind` and `self.storage`? Both are used to determine the storage type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind is probably file
or folder
. It could be derived from names, at least for standard storages provided by ARK. But developers could also create their own storages which would be unknown to ark-cli
, so the user would need to pass this information explicitly.
We could also figure out the storage type automatically by checking the path. But with atomic versions the path will always point to a folder, so we need to calculate depth of the folder. Folder storages would have depth of 3 (storage/entry/version/value
), while file storage should have depth 2 (a file inside each version, i.e. storage/version/table
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind is probably
file
orfolder
.
Right.
storage
: Required parameter of typeString
. Gets passed totranslate_storage()
to determine the file path andstorage_type
kind
: Optional parameter of typeStorageType
and specifies if it's a file or folder. It overwrites the value forstorage_type
Why would we need kind
if storage
already determines the storage type? Are there any cases where using kind
would come in handy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only real use-case for kind
is custom storages, i.e. when the storage is not shipped by ARK framework, but the user implemented their own instance of FileStorage
or FolderStorage
. In this case, we can't figure it out by the path. But we still can figure it out by the folder structure as I've described above.
Overall, kind
flag is more like a temporary helper. We should determine it automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
I removed the FIXME since there is a reason to have both flags
e1646c9
to
4296f73
Compare
Benchmark for bb2f958Click to view benchmark
|
Benchmark for ae97c7fClick to view benchmark
|
Benchmark for 3bf3092Click to view benchmark
|
@tareknaser could you investigate where does this output come from? We need to register a bug, I guess.
|
Benchmark for 7b93af4Click to view benchmark
|
Benchmark for fd60a3bClick to view benchmark
|
I have traced this down and apparently, Here's the relevant code https://github.com/ARK-Builders/ark-rust/blob/main/ark-cli/src/main.rs#L161-L170 : EntryOutput::Link => match File::open(path) {
Ok(mut file) => {
let mut contents = String::new();
match file.read_to_string(&mut contents) {
Ok(_) => (None, None, Some(contents)),
Err(_) => return None,
}
}
Err(_) => return None,
}, To address this, I have pushed a commit to check if the file content is a valid link before printing it. This is a bit of a workaround. |
If a follow-up issue is needed, feel free to register it. I think, we can merge the PR but please remove the last 2 |
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
Signed-off-by: Tarek <[email protected]>
2ec4eeb
to
02c76db
Compare
Benchmark for edebd94Click to view benchmark
|
Description
Previously,
ark-cli
logic was concentrated in a few files, with large files such asark-cli/src/main.rs
containing all the logic for running the CLI by calling other functions. This made it difficult to debug, patch, and read the code. This PR is the first step towards addressing other issues within the crate.Changes
pub enum Commands
.run()
method to handle the logic for each command.main()
function now only callsrun()
, and if an error is encountered, it prints it to stderr. This enhances error handling.unwrap()
when applicable.FIXME
notes to track planned changes.