Skip to content

Commit

Permalink
Project separated into individual crates
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Jan 18, 2024
1 parent fc5789a commit 395dde7
Show file tree
Hide file tree
Showing 34 changed files with 198 additions and 129 deletions.
40 changes: 3 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
[package]
name = "devmode"
version = "0.3.0"
edition = "2021"
license = "GPL-2.0"
description = "Devmode is a project management utility for developers."
homepage = "https://devmode.edfloreshz.dev/"
documentation = "https://docs.rs/devmode"
repository = "https://github.com/edfloreshz/devmode/"
readme = "README.md"
exclude = [
".idea",
".github",
".vscode",
"assets/img",
"assets/scripts",
]

[[bin]]
name = "dm"
path = "src/main.rs"

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

[dependencies]
libset = "0.1.2"
clap = { version = "3.2.14", features = ["derive"] }
anyhow = "1.0.44"
requestty = "0.4.1"
colored = "2.0.0"
regex = "1.5.4"
git2 = "0.14.4"
git2_credentials = "0.8.0"
cmd_lib = "1.1.0"
walkdir = "2.3.2"
serde = { version = "1.0.126", features = ["derive"] }
fs_extra = "1.2.0"
[workspace]
resolver = "2"
members = ["gui", "cli"]
18 changes: 18 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

# These are backup files generated by rustfmt
**/*.rs.bk
*/target
Cargo.lock
*.out
/.out/
/.idea
*.DS_Store
.vscode
.tasks
.vimspector.json
File renamed without changes.
32 changes: 32 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "devmode"
version = "0.3.0"
edition = "2021"
license = "GPL-2.0"
description = "Devmode is a project management utility for developers."
homepage = "https://devmode.edfloreshz.dev/"
documentation = "https://docs.rs/devmode"
repository = "https://github.com/edfloreshz/devmode/"
readme = "README.md"
exclude = [".idea", ".github", ".vscode", "assets/img", "assets/scripts"]

[[bin]]
name = "dm"
path = "src/main.rs"

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

[dependencies]
devmode-shared = { path = "../shared" }
libset = "0.1.2"
clap = { version = "3.2.14", features = ["derive"] }
anyhow = "1.0.44"
requestty = "0.4.1"
colored = "2.0.0"
regex = "1.5.4"
git2 = "0.14.4"
git2_credentials = "0.8.0"
cmd_lib = "1.1.0"
walkdir = "2.3.2"
serde = { version = "1.0.126", features = ["derive"] }
fs_extra = "1.2.0"
File renamed without changes.
File renamed without changes.
43 changes: 33 additions & 10 deletions src/cli/mod.rs → cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use requestty::Answer;
use std::fs;
use std::path::PathBuf;

use crate::constants::messages::*;
use devmode_shared::constants::messages::*;

use crate::commands::fork::ForkAction;
use crate::commands::host::Host;
use crate::commands::input::{
use crate::input::{
clone_setup, config_all, config_editor, config_host, config_owner, fork_setup, select_repo,
};
use crate::commands::project::{create_paths_reader, find_paths, OpenAction};
use crate::commands::settings::Settings;
use crate::{commands::clone::CloneAction, constants::patterns::GIT_URL};
use devmode_shared::fork::ForkAction;
use devmode_shared::host::Host;
use devmode_shared::project::{create_paths_reader, find_paths, OpenAction};
use devmode_shared::settings::Settings;
use devmode_shared::{clone::CloneAction, constants::patterns::GIT_URL};

#[derive(Parser, Debug)]
#[clap(name = "(Dev)mode", version = "0.3.0")]
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Cli {
let mut clone = if args.is_empty() {
clone_setup()?
} else if args.len() == 1 && args.get(0).unwrap().contains("http") {
clone.set_url(args.get(0))?
clone.set_url(args.get(0).cloned())
} else if args.len() == 3 {
clone
.set_host(Some(Host::from(args.get(0).unwrap())))
Expand All @@ -203,10 +203,33 @@ impl Cli {
clone.run()
}
fn open(project: &str) -> Result<()> {
OpenAction::new(project).open()
let reader = create_paths_reader()?;
let paths = find_paths(reader, project)?;
if paths.is_empty() {
bail!(NO_PROJECT_FOUND)
} else if paths.len() > 1 {
let paths: Vec<&str> = paths.iter().map(|s| s as &str).collect();
let path = select_repo(paths)
.with_context(|| "Failed to set repository.")?
.to_string();
OpenAction::new(project).open(vec![path])
} else {
OpenAction::new(project).open(paths)
}
}
fn update(project: &str) -> Result<()> {
OpenAction::new(project).update()
let reader = create_paths_reader()?;
let paths = find_paths(reader, project)?;
if paths.is_empty() {
bail!(NO_PROJECT_FOUND)
} else if paths.len() > 1 {
eprintln!("{}", MORE_PROJECTS_FOUND); // TODO: Let user decide which
let paths: Vec<&str> = paths.iter().map(|s| s as &str).collect();
let path = select_repo(paths).with_context(|| "Failed to set repository.")?;
OpenAction::new(project).update(vec![path])
} else {
OpenAction::new(project).update(paths)
}
}
fn fork(args: &[String], upstream: &str, rx: Regex) -> Result<()> {
let action = if args.is_empty() {
Expand Down
12 changes: 6 additions & 6 deletions src/commands/input.rs → cli/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::commands::application::Application;
use crate::commands::clone::CloneAction;
use crate::commands::editor::Editor;
use crate::commands::fork::ForkAction;
use crate::commands::host::Host;
use crate::commands::settings::Settings;
use anyhow::{bail, Context, Result};
use devmode_shared::application::Application;
use devmode_shared::clone::CloneAction;
use devmode_shared::editor::Editor;
use devmode_shared::fork::ForkAction;
use devmode_shared::host::Host;
use devmode_shared::settings::Settings;
use requestty::{Answer, Question};

pub fn clone_setup() -> Result<CloneAction> {
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs → cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use colored::Colorize;
use cli::Cli;

mod cli;
mod commands;
mod constants;
mod input;

fn main() -> Result<()> {
let cli = Cli::parse();
Expand Down
File renamed without changes.
7 changes: 5 additions & 2 deletions src/ui/slint/Cargo.toml → gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "slint"
name = "devmode-gui"
version = "0.1.0"
authors = ["Eduardo Flores <edfloreshz@gmail.com>"]
edition = "2021"
build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "dmg"
path = "src/main.rs"

[dependencies]
devmode-shared = { path = "../shared" }
slint = "1.0"

[build-dependencies]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use devmode_shared::clone::CloneAction;

slint::include_modules!();

fn main() -> Result<(), slint::PlatformError> {
let ui = AppWindow::new()?;

ui.global::<CloneLogic>().on_clone(move |url| {
match CloneAction::new().set_url(Some(url.to_string())).run() {
Ok(_) => {}
Err(err) => eprintln!("{err}"),
};
});

ui.run()
}
13 changes: 6 additions & 7 deletions src/ui/slint/ui/appwindow.slint → gui/ui/appwindow.slint
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Button, VerticalBox, HorizontalBox, GroupBox, TabWidget, CheckBox } from "std-widgets.slint";
import { ClonePage } from "pages/clone.slint";
import { Open } from "pages/open.slint";
import { Workspaces } from "pages/workspaces.slint";
import { Configuration } from "pages/configuration.slint";
import { Logic } from "pages/logic.slint";
import { Clone, CloneLogic } from "pages/clone.slint";
import { Open, OpenLogic } from "pages/open.slint";
import { Workspaces, WorkspacesLogic } from "pages/workspaces.slint";
import { Configuration, ConfigurationLogic } from "pages/configuration.slint";

export { Logic }
export { CloneLogic, OpenLogic, WorkspacesLogic, ConfigurationLogic }

export component AppWindow inherits Window {
VerticalBox {
Expand All @@ -15,7 +14,7 @@ export component AppWindow inherits Window {
TabWidget {
Tab {
title: "Clone";
ClonePage {}
Clone {}
}

Tab {
Expand Down
11 changes: 7 additions & 4 deletions src/ui/slint/ui/pages/clone.slint → gui/ui/pages/clone.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { VerticalBox , StandardListView, GroupBox , LineEdit, Button, HorizontalBox, Switch } from "std-widgets.slint";
import { Logic } from "logic.slint";

export component ClonePage inherits VerticalBox {
export global CloneLogic {
callback clone(string);
}

export component Clone inherits VerticalBox {

in-out property <bool> upstream-toggled;
callback clone(string);
Expand All @@ -24,7 +27,7 @@ export component ClonePage inherits VerticalBox {
}
url := LineEdit {
height: 40px;
text: "Test";
text: "https://github.com/edfloreshz/config";
}
Switch {
checked <=> root.upstream-toggled;
Expand All @@ -44,7 +47,7 @@ export component ClonePage inherits VerticalBox {
Button {
text: "Clone";
clicked => {
Logic.clone(url.text)
CloneLogic.clone(url.text)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { VerticalBox, HorizontalBox, StandardListView, LineEdit, ComboBox , Switch, GroupBox} from "std-widgets.slint";

export global ConfigurationLogic {
}

export component Configuration inherits VerticalBox {
in-out property <bool> custom-editor-enabled;
in-out property <string> custom-editor;
Expand Down
4 changes: 4 additions & 0 deletions src/ui/slint/ui/pages/open.slint → gui/ui/pages/open.slint
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { VerticalBox , StandardListView, Button } from "std-widgets.slint";

export global OpenLogic {
}

export component Open inherits VerticalBox {
StandardListView {
current-item: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { VerticalBox , StandardListView, Button } from "std-widgets.slint";

export global WorkspacesLogic {
}

export component Workspaces inherits VerticalBox {
StandardListView {
current-item: 0;
Expand Down
18 changes: 18 additions & 0 deletions shared/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html

# These are backup files generated by rustfmt
**/*.rs.bk
*/target
Cargo.lock
*.out
/.out/
/.idea
*.DS_Store
.vscode
.tasks
.vimspector.json
20 changes: 20 additions & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "devmode-shared"
version = "0.1.0"
edition = "2021"

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

[dependencies]
libset = "0.1.2"
clap = { version = "3.2.14", features = ["derive"] }
anyhow = "1.0.44"
requestty = "0.4.1"
colored = "2.0.0"
regex = "1.5.4"
git2 = "0.14.4"
git2_credentials = "0.8.0"
cmd_lib = "1.1.0"
walkdir = "2.3.2"
serde = { version = "1.0.126", features = ["derive"] }
fs_extra = "1.2.0"
File renamed without changes.
12 changes: 6 additions & 6 deletions src/commands/clone.rs → shared/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use git2_credentials::CredentialHandler;
use libset::routes::home;
use regex::bytes::Regex;

use crate::commands::git_pull;
use crate::commands::host::Host;
use crate::commands::project::OpenAction;
use crate::constants::messages::*;
use crate::constants::patterns::{ORG_GIT_URL, REGULAR_GIT_URL};
use crate::git_pull;
use crate::host::Host;
use crate::project::OpenAction;

#[derive(Clone)]
pub struct CloneAction {
Expand Down Expand Up @@ -51,9 +51,9 @@ impl CloneAction {
self.repos = repos;
self
}
pub fn set_url(mut self, url: Option<&String>) -> Result<Self> {
self.url = url.cloned();
Ok(self)
pub fn set_url(mut self, url: Option<String>) -> Self {
self.url = url;
self
}
pub fn set_workspace(mut self, workspace: Option<String>) -> Self {
self.workspace = workspace;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/commands/editor.rs → shared/src/editor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use crate::commands::application::Application;
use crate::application::Application;

#[derive(Serialize, Deserialize, Debug, Clone, Default, Eq, PartialEq)]
pub struct Editor {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/fork.rs → shared/src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use git2::Repository;
use libset::routes::home;
use regex::bytes::Regex;

use crate::commands::host::Host;
use crate::commands::project::OpenAction;
use crate::constants::messages::*;
use crate::host::Host;
use crate::project::OpenAction;

pub struct ForkAction {
pub host: Host,
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 395dde7

Please sign in to comment.