-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,18 +1,71 @@ | ||
use crate::cli::actions::Action; | ||
use anyhow::Result; | ||
use rusqlite::Connection; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
/// Handle the create action | ||
pub fn handle(action: Action) -> Result<()> { | ||
match action { | ||
Action::New { | ||
name, | ||
directory: _, | ||
file: _, | ||
exclude: _, | ||
config, | ||
directory, | ||
file, | ||
exclude, | ||
} => { | ||
println!("Creating new project: {}", name); | ||
let db_path = config.join(format!("{}.db", name)); | ||
|
||
create_db_tables(db_path)?; | ||
|
||
if let Some(directory) = directory { | ||
for dir in directory { | ||
println!("Directory: {}", fs::canonicalize(dir)?.display()); | ||
} | ||
} | ||
|
||
if let Some(file) = file { | ||
for file in file { | ||
println!("File: {}", fs::canonicalize(file)?.display()); | ||
} | ||
} | ||
|
||
if let Some(exclude) = exclude { | ||
for exclude in exclude { | ||
println!("Exclude: {}", exclude); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn create_db_tables(db_path: PathBuf) -> Result<()> { | ||
let conn = Connection::open(db_path)?; | ||
|
||
// create the tables | ||
conn.execute( | ||
"CREATE TABLE IF NOT EXISTS Directory ( | ||
id INTEGER PRIMARY KEY, | ||
name TEXT NOT NULL, | ||
parent_id INTEGER, | ||
FOREIGN KEY (parent_id) REFERENCES Directory (id) | ||
)", | ||
[], | ||
)?; | ||
|
||
conn.execute( | ||
"CREATE TABLE IF NOT EXISTS File ( | ||
id INTEGER PRIMARY KEY, | ||
name TEXT NOT NULL, | ||
size INTEGER NOT NULL, | ||
directory_id INTEGER, | ||
hash TEXT NOT NULL, | ||
FOREIGN KEY (directory_id) REFERENCES Directory (id) | ||
)", | ||
[], | ||
)?; | ||
|
||
Ok(()) | ||
} |
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