Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
megatank58 committed Apr 23, 2023
1 parent 1226ff0 commit 63d69a9
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 140 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
matrix:
include:
- target: x86_64-pc-windows-gnu
name: oxup.exe
name: oxate.exe
- target: x86_64-unknown-linux-musl
name: oxup
name: oxate
- target: x86_64-apple-darwin
name: oxup-darwin
name: oxate-darwin
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
Expand Down
1 change: 0 additions & 1 deletion .version

This file was deleted.

31 changes: 11 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxup"
version = "2.6.3"
name = "oxate"
version = "2.7.0"
edition = "2021"

[profile.release]
Expand All @@ -13,4 +13,4 @@ clap = { version = "4.0.9", features = ["derive"] }
reqwest = { version = "0.10", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.18", features = ["macros"] }
tokio = { version = "0.2.25", features = ["macros"] }
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Oxup
# Oxate

Oxup is a tool for managing installations and packages of oxido.
Oxate is a tool for managing installations and packages of oxido.

## Installation

Expand All @@ -13,7 +13,7 @@ Then you can restart your shell and install oxido.
## Usage

```bash
oxup <command> [OPTIONS]
oxate <command> [OPTIONS]
```

| Command | Description |
Expand Down
27 changes: 11 additions & 16 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
BLUE='\033[0;34m'
NONE='\033[0m'
PREFIX="${BLUE}=>${NONE} "
echo -e "${PREFIX}Downloading oxup"
echo -e "${PREFIX}Downloading oxate"

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
curl -LO https://github.com/oxidic/oxup/releases/latest/download/oxup
chmod +x oxup
./oxup setup -n
curl -LO https://github.com/oxidic/oxate/releases/latest/download/oxate
chmod +x oxate
./oxate setup
elif [[ "$OSTYPE" == "darwin"* ]]; then
curl -LO https://github.com/oxidic/oxup/releases/latest/download/oxup-darwin
chmod +x oxup-darwin
./oxup-darwin setup -n
curl -LO https://github.com/oxidic/oxate/releases/latest/download/oxate-darwin
chmod +x oxate-darwin
./oxate-darwin setup
else
curl -LO https://github.com/oxidic/oxup/releases/latest/download/oxup.exe
./oxup.exe setup -n
curl -LO https://github.com/oxidic/oxate/releases/latest/download/oxate.exe
./oxate.exe setup
fi

if [[ $SHELL == *bash ]]; then
echo '. "$HOME/.oxido/env"' >> $HOME/.bashrc
elif [[ $SHELL == *zsh ]]; then
echo '. "$HOME/.oxido/env"' >> $HOME/.zshrc
else
echo -e "${PREFIX}Add the following lines to your shell configuration to add oxup to PATH: \`. \"$HOME/.oxido/env\"\`"
fi
echo -e "${PREFIX}Add the following lines to your shell configuration to add oxate to PATH: \`. \"$HOME/.oxido/env\"\`"

13 changes: 5 additions & 8 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ use std::fs::{create_dir_all, write};
use crate::success;

pub fn init(name: String) {
let default_function = "fn main() {
print(\"Hello world!\");
}
";
let default_function = "println(\"Hello world!\");";
let metadata = format!(
"[package]
name = {name}
version = 0.1.0
name = \"{name}\"
version = \"0.1.0\"
"
);

create_dir_all(format!("{name}/src")).unwrap();
write(format!("{name}/src/main.ox"), default_function).unwrap();
write(format!("{name}/Oxup.toml"), metadata).unwrap();
write(format!("{name}/src/main.oxi"), default_function).unwrap();
write(format!("{name}/Oxate.toml"), metadata).unwrap();

success![format!("Successfully initialised {name}!")]
}
19 changes: 9 additions & 10 deletions src/install.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::os::unix::prelude::PermissionsExt;

use std::{os::unix::prelude::PermissionsExt, env::var, fs::{write, set_permissions, Permissions}};
use crate::{info, success};
use reqwest::{
header::{HeaderMap, USER_AGENT},
Expand All @@ -19,21 +18,21 @@ pub struct ReleaseData {
assets: Vec<Release>,
}

pub async fn install(os: OS, oxup: bool) -> Result<(), Box<dyn std::error::Error>> {
pub async fn install(os: OS, oxate: bool) -> Result<(), Box<dyn std::error::Error>> {
let mut headers = HeaderMap::new();
headers.insert(USER_AGENT, "megatank58".parse().unwrap());

let target = if oxup {
"https://api.github.com/repos/oxidic/oxup/releases/latest"
let target = if oxate {
"https://api.github.com/repos/oxidic/oxate/releases/latest"
} else {
"https://api.github.com/repositories/500013933/releases/latest"
};
let client = Client::new();
let response = client.get(target).headers(headers.clone()).send().await?;
let result: ReleaseData = response.json().await?;

let bin = if oxup { "oxup" } else { "oxido" };
let home = std::env::var("HOME")?;
let bin = if oxate { "oxate" } else { "oxido" };
let home = var("HOME")?;

let filter = &match os {
OS::Mac => bin.to_owned() + "darwin",
Expand All @@ -55,7 +54,7 @@ pub async fn install(os: OS, oxup: bool) -> Result<(), Box<dyn std::error::Error

info!["Moving package"];

std::fs::write(
write(
match os {
OS::Windows => format!(r"C:\bin\{bin}.exe"),
_ => {
Expand All @@ -66,9 +65,9 @@ pub async fn install(os: OS, oxup: bool) -> Result<(), Box<dyn std::error::Error
)?;

if os == OS::Linux || os == OS::Mac {
std::fs::set_permissions(
set_permissions(
format!("{home}/.oxido/bin/{bin}"),
std::fs::Permissions::from_mode(0o770),
Permissions::from_mode(0o770),
)?;
}

Expand Down
64 changes: 15 additions & 49 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
use crate::os::OS;
use clap::{command, Parser, Subcommand, ValueEnum};

mod init;
mod install;
mod os;
mod setup;
mod uninstall;
mod update;

use crate::os::OS;
use clap::{command, Parser, Subcommand, ValueEnum};

/// Oxup is a tool for managing installations and packages of oxido.
/// Oxate is a tool for managing installations and packages of oxido.
#[derive(Parser, Debug)]
#[clap(author, version, about = "Oxup is a tool for managing installations and packages of oxido.", long_about = None)]
struct Oxup {
#[clap(author, version, about = "Oxate is a tool for managing installations and packages of oxido.", long_about = None)]
struct Oxate {
#[command(subcommand)]
command: Commands,

/// Force run as windows
#[clap(short, long, value_parser)]
windows: bool,

/// Force run as Macos
#[clap(short, long, value_parser)]
macos: bool,

/// Force run as Linux
#[clap(short, long, value_parser)]
linux: bool,

/// Do not check for updates
#[clap(short, long, value_parser)]
no_update: bool,
}

#[derive(Debug, Subcommand)]
Expand All @@ -38,65 +22,46 @@ enum Commands {
#[command()]
Install,

/// Initialize a new project
/// Create a new oxate project
#[command(arg_required_else_help = true)]
Init { file: String },
Init { name: String },

/// Setup oxup and its directories
/// Setup oxate and its directories
#[command()]
Setup,

/// Uninstall oxido
#[command()]
Uninstall,

/// Update oxido to latest version avaliable
/// Update oxido to latest version
#[command(arg_required_else_help = true)]
Update { update: Updateable },
}

#[derive(Debug, Clone, ValueEnum)]
pub enum Updateable {
Oxido,
Oxup,
Oxate,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Oxup::parse();
let args = Oxate::parse();

let mut os = OS::from();
if args.linux {
os = OS::Linux;
} else if args.macos {
os = OS::Mac;
} else if args.windows {
os = OS::Windows;
}
let os = OS::from();

match args.command {
Commands::Install => {
install::install(os, false).await?;
}
Commands::Init { file } => init::init(file),
Commands::Init { name } => init::init(name),
Commands::Uninstall => {
uninstall::uninstall(os);
}
Commands::Setup => setup::setup(os),
Commands::Update { update } => update::update(update, os).await?,
}

let current_version = env!("CARGO_PKG_VERSION");

let new_version = reqwest::get("https://raw.githubusercontent.com/oxidic/oxup/main/.version")
.await?
.text()
.await?;

if !args.no_update && current_version != new_version {
info![format!("Oxup v{new_version} is avaliable for download.")];
}

Ok(())
}

Expand All @@ -113,6 +78,7 @@ mod macros {
macro_rules! error {
($message:expr) => {
println!("{} {}", "\x1b[1m\x1b[31merror:\x1b[0m", $message)
std::process::exit(1);
};
}

Expand Down
Loading

0 comments on commit 63d69a9

Please sign in to comment.