Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions install/gojo-upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# Exit on error.
set -e

CURL_OPTIONS="--proto '=https' --tlsv1.2 -sSf -L"
INSTALL_LINK="https://raw.githubusercontent.com/whuffman36/gojo/refs/heads/main/install"

VERSION_NEWEST=$(curl ${CURL_OPTIONS} "${INSTALL_LINK}/version.txt")
VERSION_CURRENT=$(gojo --version)

if [[ "${VERSION_CURRENT}" == "${VERSION_NEWEST}" ]]; then
printf "gojo is already up to date!\n"
exit 0
fi

# Donwload gojo again
printf "upgrading gojo to version ${VERSION_NEWEST}...\n"
curl ${CURL_OPTIONS} "${INSTALL_LINK}/install.sh" | sh 1> /dev/null

if [[ $? -eq 0 ]]; then
printf "gojo upgraded successfully\n"
exit 0
else
printf "failed to upgrade gojo\n"
exit 1
fi
68 changes: 40 additions & 28 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@
# Exit on error.
set -e

VERSION="v0.1.5"
CURL_OPTIONS="--proto '=https' --tlsv1.2 -sSf -L"
INSTALL_LINK="https://raw.githubusercontent.com/whuffman36/gojo/refs/heads/main/install"
REPO="https://github.com/whuffman36/gojo"
GOJO_DIR="${HOME}/.gojo"
GOJO_BIN_DIR="${GOJO_DIR}/bin"

MAGENTA="\033[1;35m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
CLEAR="\033[0m"


info() {
printf "%b%s%b\n\n" "$MAGENTA" "$1" "$CLEAR"
printf "%b%s%b\n\n" "${MAGENTA}" "$1" "${CLEAR}"
}


success() {
printf "%b%s%b\n\n" "$GREEN" "$1" "$CLEAR"
printf "%b%s%b\n\n" "${GREEN}" "$1" "${CLEAR}"
}


warn() {
printf "%b[WARNING]: %s%b\n\n" "$YELLOW" "$1" "$CLEAR"
printf "%b[WARNING]: %s%b\n\n" "${YELLOW}" "$1" "${CLEAR}" >&2
}


error() {
printf "%b[ERROR]: %s%b\n\n" "$RED" "$1" "$CLEAR"
printf "%b[ERROR]: %s%b\n\n" "${RED}" "$1" "${CLEAR}" >&2
exit 1
}

Expand All @@ -49,7 +56,7 @@ check_sudo() {


detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "${OSTYPE}" == "darwin"* ]]; then
OS="macos"
PRINTOS="macOS"
return
Expand Down Expand Up @@ -134,12 +141,17 @@ install_gojo() {

info "Installing gojo from github..."
# Download latest release from github into ~/.gojo/bin
curl --proto '=https' --tlsv1.2 -sSf -L "https://github.com/whuffman36/gojo/releases/download/v0.1.5/gojo-${ROS}-${ARCH}" > "$HOME/.gojo/bin/gojo"
curl ${CURL_OPTIONS} "${REPO}/releases/download/${VERSION}/gojo-${ROS}-${ARCH}" > "${GOJO_BIN_DIR}/gojo"

# Set binary to be executable
chmod +x "$HOME/.gojo/bin/gojo"
chmod +x "${GOJO_BIN_DIR}/gojo"

# Download gojo-update from github into ~/.gojo/bin
if [[ ! -f "${GOJO_BIN_DIR}/gojo-upgrade" ]]; then
curl ${CURL_OPTIONS} "${INSTALL_LINK}/gojo-upgrade" > "${GOJO_BIN_DIR}/gojo-upgrade"
# Set binary to be executable
chmod +x "${GOJO_BIN_DIR}/gojo-upgrade"
fi
}


Expand All @@ -163,10 +175,10 @@ install_macos() {
install_gojo

# Add ~/.gojo/bin to PATH
echo "export PATH=\"\$PATH:\$HOME/.gojo/bin/\"" >> "$HOME/.zshrc"
echo "export PATH=\"\$PATH:${GOJO_BIN_DIR}\"" >> "${HOME}/.zshrc"

success "gojo has successfully been installed!"
printf "run '%bsource ~/.zshrc%b' in your terminal to use it,\nor start a new terminal session.\n\n" "$YELLOW" "$CLEAR"
printf "run '%bsource ~/.zshrc%b' in your terminal to use it,\nor start a new terminal session.\n\n" "${YELLOW}" "${CLEAR}"
}


Expand All @@ -187,7 +199,7 @@ install_debian() {
build-essential

pipx ensurepath
source "$HOME/.bashrc"
source "${HOME}/.bashrc"

pipx install conan

Expand All @@ -196,10 +208,10 @@ install_debian() {
install_gojo

# Add ~/.gojo/bin to PATH
echo "export PATH=\"\$PATH:\$HOME/.gojo/bin/\"" >> "$HOME/.bashrc"
echo "export PATH=\"\$PATH:${GOJO_BIN_DIR}\"" >> "${HOME}/.bashrc"

success "gojo has successfully been installed!"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "$YELLOW" "$CLEAR"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "${YELLOW}" "${CLEAR}"
}


Expand All @@ -217,7 +229,7 @@ install_fedora() {
gcc-c++

pipx ensurepath
source "$HOME/.bashrc"
source "${HOME}/.bashrc"

pipx install conan

Expand All @@ -226,10 +238,10 @@ install_fedora() {
install_gojo

# Add ~/.gojo/bin to PATH
echo "export PATH=\"\$PATH:\$HOME/.gojo/bin/\"" >> "$HOME/.bashrc"
echo "export PATH=\"\$PATH:${GOJO_BIN_DIR}\"" >> "$HOME/.bashrc"

success "gojo has successfully been installed!"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "$YELLOW" "$CLEAR"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "${YELLOW}" "${CLEAR}"
}


Expand Down Expand Up @@ -263,7 +275,7 @@ install_centos() {
gcc-c++

pipx ensurepath
source "$HOME/.bashrc"
source "${HOME}/.bashrc"

pipx install conan
else
Expand All @@ -275,10 +287,10 @@ install_centos() {
install_gojo

# Add ~/.gojo/bin to PATH
echo "export PATH=\"\$PATH:\$HOME/.gojo/bin/\"" >> "$HOME/.bashrc"
echo "export PATH=\"\$PATH:${GOJO_BIN_DIR}\"" >> "${HOME}/.bashrc"

success "gojo has successfully been installed!"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "$YELLOW" "$CLEAR"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "${YELLOW}" "${CLEAR}"
}


Expand All @@ -295,7 +307,7 @@ install_arch() {
base-devel

pipx ensurepath
source "$HOME/.bashrc"
source "${HOME}/.bashrc"

pipx install conan

Expand All @@ -304,24 +316,24 @@ install_arch() {
install_gojo

# Add ~/.gojo/bin to PATH
echo "export PATH=\"\$PATH:\$HOME/.gojo/bin/\"" >> "$HOME/.bashrc"
echo "export PATH=\"\$PATH:${GOJO_BIN_DIR}\"" >> "${HOME}/.bashrc"

success "gojo has successfully been installed!"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "$YELLOW" "$CLEAR"
printf "run '%bsource ~/.bashrc%b' in your terminal to use it,\nor start a new terminal session.\n\n", "${YELLOW}" "${CLEAR}"
}


main() {
# Create directories in the user's home directory.
mkdir -p "$HOME/.gojo"
mkdir -p "$HOME/.gojo/profiles"
mkdir -p "$HOME/.gojo/formats"
curl --proto '=https' --tlsv1.2 -sSf -L https://raw.githubusercontent.com/whuffman36/gojo/refs/heads/main/install/gojo-c-format > "$HOME/.gojo/formats/gojo-c"
curl --proto '=https' --tlsv1.2 -sSf -L https://raw.githubusercontent.com/whuffman36/gojo/refs/heads/main/install/gojo-cpp-format > "$HOME/.gojo/formats/gojo-c++"
mkdir -p "$HOME/.gojo/bin"
mkdir -p "${GOJO_DIR}"
mkdir -p "${GOJO_DIR}/profiles"
mkdir -p "${GOJO_DIR}/formats"
curl ${CURL_OPTIONS} "${INSTALL_LINK}/gojo-c-format" > "${GOJO_DIR}/formats/gojo-c"
curl ${CURL_OPTIONS} "${INSTALL_LINK}/gojo-cpp-format" > "${GOJO_DIR}/formats/gojo-c++"
mkdir -p "${GOJO_BIN_DIR}"

detect_os
info "$PRINTOS detected"
info "${PRINTOS} detected"

case "$OS" in
macos)
Expand Down
1 change: 1 addition & 0 deletions install/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.5
1 change: 1 addition & 0 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ target_sources(
refresh.cpp
run.cpp
test.cpp
update.cpp
)

target_include_directories(
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void dep(std::span<std::string_view> args);

void profile(std::span<std::string_view> args);

void update(std::span<std::string_view> args);

void info();

void help();
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/dep.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <flat_map>
Expand Down Expand Up @@ -139,7 +140,13 @@ void dep(std::span<std::string_view> args) {
}
std::string_view version { "latest" };
if (args.size() == 3) {
version = args[2];
if (!args[2].starts_with("--version=")) {
throw std::runtime_error {
"gojo dep add: argument not recognized"
};
}
constexpr std::size_t version_arg_len { 10 };
version = args[2].substr(version_arg_len);
}
switch (cfg.package_manager.value()) {
case cfg::PackageManager::Conan: {
Expand Down
15 changes: 8 additions & 7 deletions src/cmd/enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ namespace cmd {

std::optional<Command> command_from_str(std::string_view str) {
static const std::flat_map<std::string_view, Command> map {
{ "init", Command::Init }, { "build", Command::Build },
{ "run", Command::Run }, { "test", Command::Test },
{ "clean", Command::Clean }, { "fmt", Command::Format },
{ "check", Command::Check }, { "refresh", Command::Refresh },
{ "dep", Command::Dep }, { "profile", Command::Profile },
{ "info", Command::Info }, { "help", Command::Help },
{ "new", Command::New }, { "--version", Command::Version },
{ "init", Command::Init }, { "build", Command::Build },
{ "run", Command::Run }, { "test", Command::Test },
{ "clean", Command::Clean }, { "fmt", Command::Format },
{ "check", Command::Check }, { "refresh", Command::Refresh },
{ "dep", Command::Dep }, { "profile", Command::Profile },
{ "info", Command::Info }, { "help", Command::Help },
{ "new", Command::New }, { "--version", Command::Version },
{ "update", Command::Update },
};

const auto result { map.find(str) };
Expand Down
1 change: 1 addition & 0 deletions src/cmd/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum class Command : std::uint8_t {
Info,
Help,
Version,
Update,
};

std::optional<Command> command_from_str(std::string_view str);
Expand Down
73 changes: 73 additions & 0 deletions src/cmd/update.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <filesystem>
#include <format>
#include <span>
#include <stdexcept>
#include <string>
#include <string_view>

#include "src/cmd/commands.hpp"
#include "src/utils.hpp"

namespace {

constexpr std::string_view HELP {
R"({1}Command:{0}
gojo {2}update{0} {4}[options]{0}

{1}Summary:{0}
TODO

{1}Options:{0}
{4}--help{0} Configure the project with an existing gojo profile.
The profile must exist.

{4}--verbose | -v
)"
};

}

namespace cmd {

void update(std::span<std::string_view> args) {
bool verbose { false };
for (const auto arg : args) {
if (arg == "--help") {
utils::gojo_print(utils::LogLevel::Info, HELP, INFO_COLORS);
return;
}
else if (arg == "--verbose" || arg == "-v") {
verbose = true;
}
else {
throw std::runtime_error {
std::format("gojo update: argument not recognized: {}", arg)
};
}
}

constexpr std::string_view install_link {
"https://raw.githubusercontent.com/whuffman36/gojo/refs/heads/main/install"
};
constexpr std::string_view curl_args {
"--proto '=https' --tlsv1.2 -sSf -L"
};
constexpr std::string_view script_name { "gojo-upgrade" };
const std::filesystem::path gojo_bin_dir { utils::get_home_dir() / ".gojo" /
"bin" };

utils::gojo_print(utils::LogLevel::Status, "Fetching latest version...");
const std::string cmd { std::format(
"curl {0} {1}/{2} > {3}/{2}",
curl_args, // {0}
install_link, // {1}
script_name, // {2}
gojo_bin_dir.string() // {3}
) };
const auto result { utils::execute_command(cmd.c_str(), false, verbose) };
if (!result.success) {
throw std::runtime_error { "failed to fetch latest version" };
}
}

} // namespace cmd
Loading
Loading