Skip to content

Commit

Permalink
add(features) + refactor(unlink + bulk_delete): Features to compile e…
Browse files Browse the repository at this point in the history
…verything from hand + unlink and bulk_delete simplify
  • Loading branch information
Thumuss committed Aug 23, 2024
1 parent 7ca5be6 commit 2daf82b
Show file tree
Hide file tree
Showing 17 changed files with 999 additions and 280 deletions.
808 changes: 706 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 27 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ edition = "2021"

[dependencies]
dirs = "5.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_with = "1.0"
toml = { version = "^0.8.14", features = ["display"] }
inquire = "0.6.2"
inquire = { version = "0.6.2", optional=true }
semver = { version = "1.0.18", features = ["serde"] }
spdx = { version = "0.10.2", features = ["text"] }
spdx = { version = "0.10.2", features = ["text"], optional = true }
clap = { version = "4.4.2", features = ["derive"] }
git2 = "^0.19.0"
strum = { version = "0.26.2", features = ["derive"] }
git2 = { version = "^0.19.0", optional = true }
typst-project = { git = "https://github.com/tingerrr/typst-project", rev = "8462942ef0c783acf339e715b5e24b2dba423de1" }
openssl = { version = "0.10", features = ["vendored"] }
openssl = { version = "0.10", features = ["vendored"] } # ?
tracing = { version = "0.1.40", features = ["attributes"] }
tracing-subscriber = "0.3.18"
clap_complete = "4.5.12"
clap_complete = { version = "4.5.12", optional = true }
shadow-rs = "0.31.1"
typst-kit = { git = "https://github.com/typst/typst" }
typst-syntax = { git = "https://github.com/typst/typst" }
regex = "1.10.6"
ignore = "0.4.22"
typst-syntax = { git = "https://github.com/typst/typst", optional = true }
regex = { version = "1.10.6", optional = true }
ignore = { version = "0.4.22", optional = true }
octocrab = { version = "0.39.0", optional = true }

[build-dependencies]
shadow-rs = "0.31.1"
Expand All @@ -37,14 +35,26 @@ name = "utpm"
path = "src/main.rs"
build = "build.rs"

[[bin]]
name = "utpm-ci"
path = "src/ci.rs"
build = "build.rs"

[features]
ci = []
default = ["full"]
nightly = []
full = ["workspace", "packages", "generate"]
add = ["install"]
bulk_delete = ["unlink"]
clone = ["dep:regex", "dep:git2", "dep:typst-syntax"]
init = ["dep:spdx", "dep:inquire"]
delete = []
generate = ["dep:clap_complete"]
install = ["link", "dep:git2"]
link = []
list = []
path = []
publish = ["dep:git2", "dep:octocrab", "dep:ignore"]
tree = []
unlink = ["dep:inquire", "dep:regex"]
workspace = ["link", "init", "install", "add", "delete", "publish", "clone"]
packages = ["tree", "list", "path", "unlink", "bulk_delete"]


# For future dependencies check and other things, it will be usefull
# Reduce size
Expand Down
21 changes: 0 additions & 21 deletions src/ci.rs

This file was deleted.

100 changes: 79 additions & 21 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
// Linker
#[cfg(feature = "add")]
pub mod add;
#[cfg(feature = "bulk_delete")]
pub mod bulk_delete;
#[cfg(feature = "clone")]
pub mod clone;
pub mod create;
#[cfg(feature = "delete")]
pub mod delete;
#[cfg(feature = "generate")]
pub mod generate;
#[cfg(feature = "init")]
pub mod init;
#[cfg(feature = "install")]
pub mod install;
#[cfg(feature = "link")]
pub mod link;
#[cfg(feature = "list")]
pub mod list;
#[cfg(feature = "path")]
pub mod package_path;
#[cfg(feature = "publish")]
pub mod publish;
#[cfg(feature = "tree")]
pub mod tree;
#[cfg(feature = "unlink")]
pub mod unlink;

#[cfg(any(feature = "clone", feature = "publish"))]
use std::path::PathBuf;

use clap::{Parser, Subcommand};
#[cfg(feature = "generate")]
use clap_complete::Shell;
use tracing::level_filters::LevelFilter;

#[cfg(feature = "init")]
use typst_project::manifest::{categories::Category, disciplines::Discipline};

use crate::build;

#[derive(Parser, Clone, Debug, PartialEq)]
pub struct CreateInitArgs {
#[cfg(feature = "init")]
pub struct InitArgs {
/// Desactivate interactive session
#[arg(short = 'm', long, requires = "ni")]
cli: bool,
Expand Down Expand Up @@ -106,6 +124,7 @@ pub struct CreateInitArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "link")]
pub struct LinkArgs {
/// Force the copy of the dir / creation of the symlink
#[arg(short, long)]
Expand All @@ -117,6 +136,7 @@ pub struct LinkArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(any(feature = "list", feature = "tree"))]
pub struct ListTreeArgs {
/// Will list all packages including @preview
#[arg(short, long)]
Expand All @@ -128,6 +148,7 @@ pub struct ListTreeArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "publish")]
pub struct PublishArgs {
#[arg()]
path: Option<PathBuf>,
Expand Down Expand Up @@ -157,13 +178,15 @@ pub struct PublishArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "generate")]
pub struct GenerateArgs {
/// The type of your shell
#[arg(value_enum)]
generator: Shell,
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "clone")]
pub struct CloneArgs {
/// The name of the package you want to clone
#[arg()]
Expand Down Expand Up @@ -191,28 +214,18 @@ pub struct CloneArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "unlink")]
pub struct UnlinkArgs {
/// The name of the package
name: Option<String>,

/// Namespace, where your packages are install (default local)
#[arg(short, long)]
namespace: Option<String>,

/// Do you want to delete the namespace or not
#[arg(short, long)]
delete_namespace: bool,

/// The version you want to delete, if nothing has been provided it will be the whole package
#[arg(short, long)]
version: Option<semver::Version>,
package: String,

/// Confirm the deletion of a dir
#[arg(short, long)]
yes: bool,
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "bulk_delete")]
pub struct BulkDeleteArgs {
/// Names of your packages, use version with this syntax: mypackage:1.0.0
#[clap(value_delimiter = ',')]
Expand All @@ -224,6 +237,7 @@ pub struct BulkDeleteArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "install")]
pub struct InstallArgs {
/// If you want to install a specific package
#[arg(num_args = 1..)]
Expand All @@ -235,88 +249,132 @@ pub struct InstallArgs {
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "delete")]
pub struct DeleteArgs {
/// URIs to remove.
pub uri: Vec<String>,
}

#[derive(Parser, Clone, Debug, PartialEq)]
#[cfg(feature = "add")]
pub struct AddArgs {
/// The url or path of your repository.
pub uri: Vec<String>,
}

/// Commands to use packages related to typst
#[derive(Subcommand, Debug, PartialEq)]
#[cfg(any(
feature = "tree",
feature = "list",
feature = "path",
feature = "unlink",
feature = "bulk_delete"
))]
pub enum Packages {
/// List all of packages from your dir, in a form of a tree
#[command(visible_alias = "t")]
#[cfg(feature = "tree")]
Tree(ListTreeArgs),

/// List all of packages from your dir, in a form of a list
#[command(visible_alias = "l")]
#[cfg(feature = "list")]
List(ListTreeArgs),

/// Display path to typst packages folder
#[command(visible_alias = "p")]
#[cfg(feature = "path")]
Path,

/// Delete package previously install with utpm
#[command(visible_alias = "u")]
#[cfg(feature = "unlink")]
Unlink(UnlinkArgs),

#[command(visible_alias = "bd")]
#[cfg(feature = "bulk_delete")]
BulkDelete(BulkDeleteArgs),
}

/// Commands to create, edit, delete your workspace for your package.
#[derive(Subcommand, Debug, PartialEq)]
#[cfg(any(
feature = "link",
feature = "init",
feature = "install",
feature = "add",
feature = "delete",
feature = "init",
feature = "publish",
feature = "clone"
))]
pub enum Workspace {
/// Link your project to your dirs
#[command(visible_alias = "l")]
#[cfg(feature = "link")]
Link(LinkArgs),

/// Create a file for your project (typst.toml)
/// (deprecated, use `utpm workspace init`)
#[command(visible_alias = "c")]
Create(CreateInitArgs),

/// Install all dependencies from the `typst.toml`
#[command(visible_alias = "i")]
#[cfg(feature = "install")]
Install(InstallArgs),

/// Add dependencies and then install them
#[command(visible_alias = "a")]
#[cfg(feature = "add")]
Add(AddArgs),

/// Delete dependencies
#[command(visible_alias = "d")]
#[cfg(feature = "delete")]
Delete(DeleteArgs),

/// Create your workspace to start a typst package
Init(CreateInitArgs),
#[cfg(feature = "init")]
Init(InitArgs),

/// WIP
#[command(visible_alias = "p")]
#[cfg(feature = "publish")]
Publish(PublishArgs),

/// WIP
#[command()]
#[cfg(feature = "clone")]
Clone(CloneArgs),
}

#[derive(Subcommand, Debug, PartialEq)]
pub enum Commands {
#[command(subcommand)]
#[command(visible_alias = "ws")]
#[cfg(any(
feature = "link",
feature = "init",
feature = "install",
feature = "add",
feature = "delete",
feature = "init",
feature = "publish",
feature = "clone"
))]
Workspace(Workspace),

#[command(subcommand)]
#[command(visible_alias = "pkg")]
#[cfg(any(
feature = "tree",
feature = "list",
feature = "path",
feature = "unlink",
feature = "bulk_delete"
))]
Packages(Packages),

/// Generate shell completion
#[command(visible_alias = "gen")]
#[cfg(feature = "generate")]
Generate(GenerateArgs),
}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing::{debug, instrument, trace};
use typst_project::manifest::{tool::Tool, Manifest};

use crate::{
manifest,
load_manifest,
utils::{
paths::get_current_dir,
specs::Extra,
Expand All @@ -18,7 +18,7 @@ use super::{install, AddArgs, InstallArgs};

#[instrument]
pub fn run(cmd: &mut AddArgs) -> Result<bool> {
let mut config: Manifest = manifest!();
let mut config: Manifest = load_manifest!();
if cmd.uri.len() == 0 {
debug!("0 URI found in cmd.uri");
return Err(Error::new(
Expand All @@ -39,7 +39,7 @@ pub fn run(cmd: &mut AddArgs) -> Result<bool> {
for e in &cmd.uri {
match dependencies.iter().position(|x| x == e) {
Some(_) => {
trace!("{} dependency already in the manifest, skipping", e);
trace!("{} dependency already in the load_manifest skipping", e);
}
None => {
trace!("{} added", e);
Expand Down
Loading

0 comments on commit 2daf82b

Please sign in to comment.