Expand description
In this module functions from commands
module
executes using commands in CLI.
§About module
First of all, the LNotebook
was created so that you can
quickly and easily write your own notebook. This module was created so that you can run the notebook
right away without manually using the functions from the commands
module,
and it also demonstrates how you could use LNotebook
. So if this way of using
the LNotebook
doesn’t suit you, just write your own way to use it.
§How use commands
To begin you should write some code that will
call NoteCommand::new
and NoteCommand::execute_command
.
For example, this is what the code from notebook_example
that meets the requirements looks like:
// --snip--
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::new("debug"))
.init();
// Get database URL from enivroment variable
let db_url = get_db_url().await?;
// Connecting to database
let db = PgPool::connect(&db_url).await?;
event!(Level::DEBUG, "Connect to db");
// Converting CLI command variable to NoteCommand option
let a = NoteCommand::new().await?;
// Execute the selected command
a.execute_command(&db).await?;
event!(Level::DEBUG, "Command executed");
Ok(())
}
To use these commands you must use:
cargo run -- `your-command`
§List of all commands you can call from CLI:
add-note <notename>
- will prompt to enter new note that will be added to the notebook undernotename
.del-note <notename>
- deletes note withnotename
if it exist.del-all
- deletes all total notes from the notebook.clear-note <notename>
- clears content ofnotename
upd-note <notename>
- will prompt to enter a note that will be added instead old note innotename
.upd-notename <new notename>
- updates old notename to newnotename
of requested note.display-note <notename>
- displaysnotename
,note
and note-id
of requested note.- If you did not specify which command to execute, then all total notes will be displayed.
§Examples
Code under deletes ‘unnecessary_note’ if it exists:
cargo run -- del-note unnecessary_note
Сommands such as add-note
and upd-note
will prompt you to enter a new note. To finish write note you
should write #endnote#
at the end, as written in the tooltip.
For example the code below will update the ‘passwords’ content to
‘login: krutoy_4el\npassword: 123’ if note exists:
cargo run -- upd-note passwords
# output
Enter note you want to add instead old note in `passwords`
(At the end of the note, enter `#endnote#` to finish writing the note):
# input
login: krutoy_4el
password: 1234#endnote#
# output
Note to add into `passwords`:
login: krutoy_4el
password: 123
Let’s display full info about this note.
If you did not specify which command to execute, then all total notes will be displayed.
You also can use display-note
to display it, but for a variety we will do it like in the code below:
cargo run
# output
All notes in notebook:
ID: 1
Name: passwords
Data:
login: krutoy_4el
password: 123
If there were more notes here, they would all be displayed, but since we only have one note, we only got that one.
Structs§
- Note
Command - Contains the command as
enum
from CLI to run it later.