-
Notifications
You must be signed in to change notification settings - Fork 0
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 and minor features #63
Merged
+672
−418
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4adb30b
Rename and refactor.
floitsch 00e2e08
Refactor and minor features.
floitsch c2c2519
Rename 'info' to 'inform' and 'warning' to 'warn'.
floitsch ff61b1a
Remove spurious main.toit file.
floitsch 2679c25
Update tests.
floitsch d268544
Merge branch 'main' into floitsch/rename
floitsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2024 Toitware ApS. All rights reserved. | ||
// Use of this source code is governed by an MIT-style license that can be | ||
// found in the package's LICENSE file. | ||
|
||
import cli show * | ||
import host.file | ||
|
||
store-bytes cli/Cli: | ||
cache := cli.cache | ||
|
||
data := cache.get "my-key": | store/FileStore | | ||
// Block that is called when the key is not found. | ||
// The returned data is stored in the cache. | ||
print "Data is not cached. Computing it." | ||
store.save #[0x01, 0x02, 0x03] | ||
|
||
print data // Prints #[0x01, 0x02, 0x03]. | ||
|
||
store-directory cli/Cli: | ||
cache := cli.cache | ||
|
||
directory := cache.get-directory-path "my-dir-key": | store/DirectoryStore | | ||
// Block that is called when the key is not found. | ||
// The returned directory is stored in the cache. | ||
print "Directory is not cached. Computing it." | ||
store.with-tmp-directory: | tmp-dir | | ||
// Create a few files with some data. | ||
file.write-content --path="$tmp-dir/data1.txt" "Hello world" | ||
file.write-content --path="$tmp-dir/data2.txt" "Bonjour monde" | ||
store.move tmp-dir | ||
|
||
print directory // Prints the path to the directory. | ||
|
||
main args: | ||
// Uses the application name "cli-example" which will be used | ||
// to compute the path of the cache directory. | ||
root-cmd := Command "cli-example" | ||
--help=""" | ||
An example application demonstrating the file-cache. | ||
""" | ||
--options=[ | ||
OptionEnum "mode" ["file", "directory"] | ||
--help="Store a file in the cache." | ||
--required, | ||
] | ||
--run=:: run it | ||
root-cmd.run args | ||
|
||
run invocation/Invocation: | ||
if invocation["mode"] == "file": | ||
store-bytes invocation.cli | ||
else: | ||
store-directory invocation.cli |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe not the best verby name.
verbose
,interactive
,result
are all kind of weird now - and got a bit weirder by the info -> inform, warning -> warn cleanup.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.
I will do a follow-up PR.
As discussed in person: