Skip to content

Commit

Permalink
Reformated comments and removed append and prepend commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
gitkeeper committed Apr 10, 2024
1 parent ab7bc47 commit 74e68bf
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 76 deletions.
60 changes: 36 additions & 24 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//! # Database
//!
//! This module provides the `Database` struct which is used to interact with the SurrealDB
//! database. This struct provides methods for initializing and interacting with the database.
//! This module provides the `Database` struct which is used to interact with
//! the SurrealDB database. This struct provides methods for initializing and
//! interacting with the database.
//!
//! The `initialize` method is used to create a new instance of the `Database` struct and connect to
//! the SurrealDB database. It uses the `NAMESPACE` and `DATABASE` constants to specify the
//! namespace and database for SurrealDB to use.
//! The `initialize` method is used to create a new instance of the `Database`
//! struct and connect to //! the SurrealDB database. It uses the `NAMESPACE`
//! and `DATABASE` constants to specify the namespace and database for SurrealDB
//! to use.
//!
//! The `path` method is used to determine the path to the database file. It uses the `dirs` crate
//! to get the home directory and appends the `.pilum/database` directory to it.
//! The `path` method is used to determine the path to the database file. It
//! uses the `dirs` crate to get the home directory and appends the default
//! directory to it.
//!
use dirs::home_dir;
use std::path::PathBuf;
Expand All @@ -18,24 +21,30 @@ use surrealdb::Surreal;
type SurrealDb = Surreal<surrealdb::engine::local::Db>;
type SurrealError = surrealdb::Error;

/// The `Database` struct provides a way to interact with the SurrealDB database.
/// It does not hold any data itself, but provides methods for initializing and
/// interacting with the database.
///
pub struct Database;

impl Database {
const NAMESPACE: &'static str = "pilum";
const DATABASE: &'static str = "pilum";

/// Initializes a new instance of the `Database` struct and connects to the SurrealDB database.
/// Initializes a new instance of the `Database` struct and connects to the
/// SurrealDB database.
///
/// This method creates a new `SurrealDb` instance and sets the namespace and database to use
/// based on the `NAMESPACE` and `DATABASE` constants. It returns a `Result` that contains the
/// `SurrealDb` instance if the database connection is successful, or a `SurrealError` if the
/// connection fails.
/// This method creates a new `SurrealDb` instance and sets the namespace and
/// database to use based on the `NAMESPACE` and `DATABASE` constants. It returns
/// a `Result` that contains the `SurrealDb` instance if the database connection
/// is successful, or a `SurrealError` if the connection fails.
///
/// # Errors
///
/// This function will return an error if the SurrealDB database connection fails. This could be
/// due to a variety of reasons, such as the database file not existing, insufficient
/// permissions or a network error if the database is remote.
/// This function will return an error if the SurrealDB database connection
/// fails. This could be due to a variety of reasons, such as the database file
/// not existing, insufficient permissions or a network error if the database is
/// remote.
///
pub async fn initialize() -> Result<SurrealDb, SurrealError> {
let db = Surreal::new::<RocksDb>(Self::endpoint()).await?;
Expand All @@ -45,13 +54,15 @@ impl Database {

/// Determines the endpoint to the database file.
///
/// This method uses the `dirs` crate to get the home directory and appends the a database
/// directory to it. It returns a `PathBuf` that represents the endpoint to the database file.
/// This method uses the `dirs` crate to get the home directory and appends the
/// database directory to it. It returns a `PathBuf` that represents the
/// endpoint to the database file.
///
/// # Errors
///
/// This function will return an error if the home directory cannot be determined. This could be
/// due to a variety of reasons, such as the HOME environment variable not being set.
/// This function will return an error if the home directory cannot be
/// determined. This could be due to a variety of reasons, such as the HOME
/// environment variable not being set.
///
fn endpoint() -> PathBuf {
home_dir().unwrap().join(".pilum").join("database")
Expand All @@ -62,17 +73,18 @@ impl Database {
mod tests {
use super::*;

// This test checks the initialization of the SurrealDB database. It uses the `initialize`
// method of the `Database` struct to attempt to connect to the database. The `assert!` macro is
// then used to check that the `Result` returned by the `initialize` method is `Ok`.
// This test checks the initialization of the SurrealDB database. It uses the
// `initialize` method of the `Database` struct to attempt to connect to the
// database. The `assert!` macro is then used to check that the `Result`
// returned by the `initialize` method is `Ok`.
#[tokio::test]
async fn test_database_initialization() {
let result = Database::initialize().await;
assert!(result.is_ok(), "Database initialization failed.");
}

// This test checks the `endpoint` function of the `Database` struct. It calls the `endpoint`
// function and asserts that the returned `PathBuf` are correct.
// This test checks the `endpoint` function of the `Database` struct. It calls
// the `endpoint` function and asserts that the returned `PathBuf` are correct.
#[test]
fn test_endpoint_function() {
let endpoint = Database::endpoint();
Expand Down
67 changes: 36 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
//!
//! This is the core library for the application.
//!
//! The `lib.rs` file contains the main structures and logic of the application. It includes the
//! `Cli` struct which is responsible for parsing command-line arguments and executing the
//! corresponding commands. It also includes the `Commands` enum which defines the available
//! commands for the application.
//! The `lib.rs` file contains the main structures and logic of the application.
//! It includes the `Cli` struct which is responsible for parsing command-line
//! arguments and executing the corresponding commands. It also includes the
//! `Commands` enum which defines the available commands for the application.
//!
//! The `Database` module is also imported in this file. It uses the SurrealDB database for data
//! persistence. The `Database` struct is used to initialize and interact with the SurrealDB
//! database. It must be used inside an asynchronous context due to its asynchronous nature.
//! The `Database` module is also imported in this file. It uses the SurrealDB
//! database for data persistence. The `Database` struct is used to initialize
//! and interact with the SurrealDB database. It must be used inside an
//! asynchronous context due to its asynchronous nature.
//!
mod database;
pub mod database;

use clap::{Parser, Subcommand};
use database::Database;

/// The `Commands` enum defines the available commands for the application.
#[derive(Debug, Subcommand)]
pub enum Commands {
/// Shows active tasks.
Expand All @@ -24,8 +26,6 @@ pub enum Commands {
Add,
/// Shows all tasks.
All,
/// Appends text to an existing task description.
Append,
/// Shows completed tasks.
Completed,
/// Deletes the specified task.
Expand All @@ -38,22 +38,22 @@ pub enum Commands {
List,
/// Modifies the existing task with provided arguments.
Modify,
/// Prepends text to an existing task description.
Prepend,
}

/// Pilum is a sophisticated task manager with a CLI and a GUI written in Rust.
///
/// Pilum serves as a convenient and easy-to-use task management tool, operated via the command line
/// and a graphical interface. It keeps track of your to-do tasks, enabling operations like adding,
/// removing and altering tasks as per your requirements. Pilum is equipped with a wide range of
/// commands for sophisticated task manipulations.
/// Pilum serves as a convenient and easy-to-use task management tool, operated
/// via the command line and a graphical interface. It keeps track of your to-do
/// tasks, enabling operations like adding, removing and altering tasks as per
/// your requirements. Pilum is equipped with a wide range of commands for
/// sophisticated task manipulations.
///
/// Essentially, Pilum functions as a list organizer. You can feed details, along with their
/// respective parameters, and the program neatly structures and displays it. By integrating
/// deadlines and recurring tasks, it becomes a comprehensive to-do manager. Further refinement
/// is achieved by incorporating elements like priorities, tags, project groups and more, making
/// Pilum a fully-fledged task organization program.
/// Essentially, Pilum functions as a list organizer. You can feed details,
/// along with their respective parameters, and the program neatly structures
/// and displays it. By integrating deadlines and recurring tasks, it becomes a
/// comprehensive to-do manager. Further refinement is achieved by incorporating
/// elements like priorities, tags, project groups and more, making Pilum a
/// fully-fledged task organization program.
///
#[derive(Parser)]
#[command(version, about)]
Expand All @@ -66,12 +66,15 @@ impl Cli {
/// The `run` function is the main entry point for the application.
///
/// It first parses the command-line arguments using the `Cli::parse` method.
/// Then, it initializes the SurrealDB database by calling the `Database::initialize` method.
/// Then, it initializes the SurrealDB database by calling the
/// `Database::initialize` method.
///
/// If the database initialization is successful, it proceeds to check if a command was provided
/// through the command-line arguments. If a command is found, it executes the command.
/// If the database initialization is successful, it proceeds to check if a
/// command was provided through the command-line arguments. If a command is
/// found, it executes the command.
///
/// This function is asynchronous because the `Database::initialize` method is asynchronous.
/// This function is asynchronous because the `Database::initialize` method is
/// asynchronous.
///
pub async fn run() {
let args = Cli::parse();
Expand All @@ -89,13 +92,15 @@ impl Cli {
mod tests {
use super::*;

/// `clap` reports most development errors as `debug_assert!`s. Rather than checking every
/// subcommand, this test catches possible problems earlier in the development cycle.
/// `clap` reports most development errors as `debug_assert!`s. Rather than
/// checking every subcommand, this test catches possible problems earlier in
/// the development cycle.
///
/// Most error states are handled as asserts under the assumption they are programming mistake and
/// not something to handle at runtime. Rather than relying on tests (manual or automated) that
/// exhaustively test the CLI to ensure the asserts are evaluated, this will run those asserts in a
/// way convenient for running as a test.
/// Most error states are handled as asserts under the assumption they are
/// programming mistake and not something to handle at runtime. Rather than
/// relying on tests (manual or automated) that exhaustively test the CLI to
/// ensure the asserts are evaluated, this will run those asserts in a way
/// convenient for running as a test.
///
#[test]
fn verify_cli() {
Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
//!
//! This is the main entry point for the application.
//!
//! The `main.rs` file is responsible for starting the application and initializing the Tokio
//! runtime environment. The Tokio runtime is used to handle asynchronous tasks throughout the
//! application.
//! The `main.rs` file is responsible for starting the application and
//! initializing the Tokio runtime environment. The Tokio runtime is used to
//! handle asynchronous tasks throughout the application.
//!
//! The `main` function uses the `#[tokio::main]` attribute to start the Tokio runtime and then
//! calls the `run` function of the `Cli` struct from the `pilum` module. The `run` function
//! handles the parsing of command-line arguments and the execution of the corresponding commands.
//! The `main` function uses the `#[tokio::main]` attribute to start the Tokio
//! runtime and then calls the `run` function of the `Cli` struct from the
//! crate module. The `run` function handles the parsing of command-line
//! arguments and the execution of the corresponding commands.
//!
//! The application uses the SurrealDB database for data persistence. The database is initialized
//! in the `run` function of the `Cli` struct.
//! The application uses the SurrealDB database for data persistence. The
//! database is initialized in the `run` function of the `Cli` struct.
//!
#[tokio::main]
async fn main() {
Expand Down
14 changes: 7 additions & 7 deletions tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//!
//! This is a test operation for the application's command-line interface (CLI).
//!
//! `trycmd::TestCases::new()` creates a new set of test cases. Each `.case()` method appends a new
//! test case. The paths in the arguments represent test files which contain the definition of each
//! test case. The library `trycmd` reads these `.md` files and the CLI tests will appraise
//! different sets of commands based on these definitions.
//! `trycmd::TestCases::new()` creates a new set of test cases. Each `.case()`
//! method appends a new test case. The paths in the arguments represent test
//! files which contain the definition of each test case. The library `trycmd`
//! reads these `.md` files and the CLI tests will appraise different sets of
//! commands based on these definitions.
//!
#[test]
fn cli_tests() {
trycmd::TestCases::new()
.case("tests/commands/*.md")
.case("README.md");
trycmd::TestCases::new().case("tests/commands/*.md");
}
6 changes: 0 additions & 6 deletions tests/commands/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ Commands:
active Shows active tasks
add Adds a new pending task to the task list
all Shows all tasks
append Appends text to an existing task description
completed Shows completed tasks
delete Deletes the specified task
done Marks the specified task as completed
duplicate Duplicates the specified tasks
list Shows most details of tasks
modify Modifies the existing task with provided arguments
prepend Prepends text to an existing task description
help Print this message or the help of the given subcommand(s)

Options:
Expand Down Expand Up @@ -51,14 +49,12 @@ Commands:
active Shows active tasks
add Adds a new pending task to the task list
all Shows all tasks
append Appends text to an existing task description
completed Shows completed tasks
delete Deletes the specified task
done Marks the specified task as completed
duplicate Duplicates the specified tasks
list Shows most details of tasks
modify Modifies the existing task with provided arguments
prepend Prepends text to an existing task description
help Print this message or the help of the given subcommand(s)

Options:
Expand All @@ -82,14 +78,12 @@ Commands:
active Shows active tasks
add Adds a new pending task to the task list
all Shows all tasks
append Appends text to an existing task description
completed Shows completed tasks
delete Deletes the specified task
done Marks the specified task as completed
duplicate Duplicates the specified tasks
list Shows most details of tasks
modify Modifies the existing task with provided arguments
prepend Prepends text to an existing task description
help Print this message or the help of the given subcommand(s)

Options:
Expand Down

0 comments on commit 74e68bf

Please sign in to comment.