Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
added minor optical improvements
fixed help text
added command "about"
updated Makefile
updated README.md
  • Loading branch information
SchokiCoder committed Jun 5, 2022
1 parent 0d1fdaf commit 70a7ffb
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 69 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[package]
name = "smng"
version = "0.1.0"
version = "2.0.0"
authors = ["SchokiCoder <afschoknecht@gmail.com>"]
repository = "https://github.com/SchokiCoder/smng"
edition = "2018"
license-file = "LICENSE"
license = "GPLv3"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sqlite = "0.26.*"
chrono = "0.4.*"
Expand Down
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

CC = cc
APP_NAME = smng
CFLAGS = -std=c99 -Wall -Wextra -O3
LIBS = -lschoki_misc -lsqlite3
INCLUDE = -I /usr/include/schoki_misc

INSTALL_BIN_DIR = /usr/bin
USERNAME = ""

options:
@echo smng build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "CC = ${CC}"
@echo "LIBS = ${LIBS}"
info:
@echo "1. Set username in Makefile.\n2. make install"

clean:
rm -f ${APP_NAME} *.o

install:
${CC} src/*.c ${CFLAGS} ${INCLUDE} ${LIBS} -o ${APP_NAME}
build:
cargo rustc --release

mkconfig:
mkdir -p /etc/smng.d
echo "/home/"${USERNAME}"/.smng/worktimes.db" >> "/etc/smng.d/db_path"

install: build mkconfig
mkdir -p ${INSTALL_BIN_DIR}
mv -f ${APP_NAME} ${INSTALL_BIN_DIR}
mv -f ./target/release/${APP_NAME} ${INSTALL_BIN_DIR}
chmod 755 ${INSTALL_BIN_DIR}/${APP_NAME}

uninstall:
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ Personal working time manager, to monitor the time you worked on each project.

## Dependencies

+ [sqlite3](https://sqlite.org/)
+ [schoki_misc](https://github.com/SchokiCoder/schoki_misc.git)
+ [sqlite](https://docs.rs/sqlite/)
+ [chrono](https://docs.rs/chrono/)
+ [term_size](https://docs.rs/term_size/)

## Installation

```
git clone https://github.com/SchokiCoder/smng.git
cd smng
mv src/config.def.h src/config.h
sudo make
make info
* follow instructions *
sudo make install
```

## Example

```
smng ap "MyNewProject"
smng r -1
smng r 1
* later *
Expand Down
21 changes: 0 additions & 21 deletions src/app.rs

This file was deleted.

75 changes: 57 additions & 18 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use super::app;
use chrono::prelude::*;

pub const HELP_INFO: &str = "prints all help messages";
pub const HELP_NAME: &str = "help";
pub const HELP_ABBR: &str = "h";

pub const ABOUT_INFO: &str = "prints information about the application";
pub const ABOUT_NAME: &str = "about";
pub const ABOUT_ABBR: &str = "abt";

pub const ADD_PROJECT_INFO: &str = "add a project";
pub const ADD_PROJECT_NAME: &str = "add-project";
pub const ADD_PROJECT_ABBR: &str = "ap";
Expand Down Expand Up @@ -56,7 +60,7 @@ pub const STOP_ARGS: &str = "description";
pub const ADD_RECORD_INFO: &str = "add a new complete record";
pub const ADD_RECORD_NAME: &str = "add-record";
pub const ADD_RECORD_ABBR: &str = "ar";
pub const ADD_RECORD_ARGS: &str = "PROJECT_ID DESCRIPTION YEAR MONTH DAY HOUR MINUTE YEAR MONTH DAY HOUR MINUTE";
pub const ADD_RECORD_ARGS: &str = "project_id description year month day hour minute year month day hour minute";

pub const EDIT_RECORD_PROJECT_INFO: &str = "edit record's project";
pub const EDIT_RECORD_PROJECT_NAME: &str = "edit-record-project";
Expand Down Expand Up @@ -113,15 +117,22 @@ pub fn print_cmd_help(info: &str, name: &str, abbr: Option<&str>, args: Option<&

const ETC_DB_PATH: &str = "/etc/smng.d/db_path";

use std::io::Read;

fn database_open() -> sqlite::Connection {
// read db path config
let mut f = std::fs::File::open(ETC_DB_PATH).unwrap();
let mut etc_raw = [0; 255];
let n = f.read(&mut etc_raw[..]).unwrap();
let temp = std::str::from_utf8(&etc_raw[..n]).unwrap();
let path = String::from(String::from(temp).trim());
use std::io::Read;

let f = std::fs::File::open(ETC_DB_PATH);
let path: String;

if f.is_ok() {
let mut etc_raw = [0; 255];
let n = f.unwrap().read(&mut etc_raw[..]).unwrap();
let temp = std::str::from_utf8(&etc_raw[..n]).unwrap();
path = String::from(String::from(temp).trim());
}
else {
panic!("Etc file \"{}\" could not be read.", ETC_DB_PATH);
}

// if db doesn't exist, flag
let db_empty: bool;
Expand Down Expand Up @@ -200,10 +211,19 @@ fn database_open() -> sqlite::Connection {

pub fn help() {
println!("Usage:");
println!("{} [COMMAND] [ARGS]", app::NAME);
println!("{} [COMMAND] [ARGS]", env!("CARGO_PKG_NAME"));
println!("");

print_cmd_help(HELP_INFO, HELP_NAME, Some(HELP_ABBR), None);
print_cmd_help(
HELP_INFO,
HELP_NAME,
Some(HELP_ABBR),
None);
print_cmd_help(
ABOUT_INFO,
ABOUT_NAME,
Some(ABOUT_ABBR),
None);
print_cmd_help(
ADD_PROJECT_INFO,
ADD_PROJECT_NAME,
Expand All @@ -229,8 +249,21 @@ pub fn help() {
RECORD_NAME,
Some(RECORD_ABBR),
Some(RECORD_ARGS));
print_cmd_help(STATUS_INFO, STATUS_NAME, None, None);
print_cmd_help(STOP_INFO, STOP_NAME, Some(STOP_ABBR), Some(STOP_ARGS));
print_cmd_help(
STATUS_INFO,
STATUS_NAME,
None,
None);
print_cmd_help(
STOP_INFO,
STOP_NAME,
Some(STOP_ABBR),
Some(STOP_ARGS));
print_cmd_help(
ADD_RECORD_INFO,
ADD_RECORD_NAME,
Some(ADD_RECORD_ABBR),
Some(ADD_RECORD_ARGS));
print_cmd_help(
EDIT_RECORD_PROJECT_INFO,
EDIT_RECORD_PROJECT_NAME,
Expand Down Expand Up @@ -271,8 +304,16 @@ pub fn help() {
SHOW_MONTH_NAME,
Some(SHOW_MONTH_ABBR),
Some(SHOW_MONTH_ARGS));
}

println!("You can also use negative id's to count from the other end.");
pub fn about() {
println!("{} {} is licensed under the {}.",
env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_LICENSE"));
println!("You should have received a copy of the license along with this program.");
println!("If not see <{}>\n",
"https://www.gnu.org/licenses/");
println!("The source code of this program is available at:\n{}\n",
env!("CARGO_PKG_REPOSITORY"));
}

pub fn add_project(project_name: &str) {
Expand Down Expand Up @@ -529,7 +570,7 @@ pub fn edit_record_begin(record_id: i64, year: i64, month: i64, day: i64,
hour: i64, minute: i64) {
edit_record_time(true, record_id, year, month, day, hour, minute);

println!("Record ({}) begin set to {}-{}-{} {}:{}.",
println!("Record ({}) begin set to {:04}-{:02}-{:02} {:02}:{:02}.",
record_id,
year, month, day,
hour, minute);
Expand All @@ -539,7 +580,7 @@ pub fn edit_record_end(record_id: i64, year: i64, month: i64, day: i64,
hour: i64, minute: i64) {
edit_record_time(false, record_id, year, month, day, hour, minute);

println!("Record ({}) end set to {}-{}-{} {}:{}.",
println!("Record ({}) end set to {:04}-{:02}-{:02} {:02}:{:02}.",
record_id,
year, month, day,
hour, minute);
Expand Down Expand Up @@ -740,8 +781,6 @@ fn show_records(ts_begin: i64, ts_end: i64) {
println!("Summarized worktime: {}.", worktime);
}

use chrono::prelude::*;

const DAY_SECONDS: u32 = 60 * 60 * 24;

struct WeekBeginAndEnd {
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

pub mod app;
pub mod commands;
use std::env;

Expand Down Expand Up @@ -44,14 +43,18 @@ fn main() {

// if not args given, print usage help and end
if args.len() < 2 {
println!("Usage {} COMMAND [ARGUMENTS]:", app::NAME);
println!("Try '{} {}' for more information.", app::NAME, commands::HELP_NAME);
println!("Usage {} COMMAND [ARGUMENTS]:", env!("CARGO_PKG_NAME"));
println!("Try '{} {}' for more information.",
env!("CARGO_PKG_NAME"),
commands::HELP_NAME);
return;
}

match args[1].as_str() {
commands::HELP_NAME | commands::HELP_ABBR => commands::help(),

commands::ABOUT_NAME | commands::ABOUT_ABBR => commands::about(),

commands::ADD_PROJECT_NAME | commands::ADD_PROJECT_ABBR => {
if args.len() == 2 {
commands::print_cmd_help(
Expand Down
10 changes: 5 additions & 5 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

-config v_11-52
(db_path)
-purge Utc use local ?
-make sure help text .
-make sure help text v_09-55_05-06-2022
matches reality
-makefile .
-about command v_10-31
(show version, license)
-makefile v_10-59
(also install std etc)
-README.md .
-README.md v_11-03

-v . -> 2.0.0
update app.rs, Cargo.toml
}

0 comments on commit 70a7ffb

Please sign in to comment.