Skip to content

Commit

Permalink
feat:add color and ttl check
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavankumar07s committed Nov 13, 2024
1 parent 13d7bf1 commit 0b07f2e
Show file tree
Hide file tree
Showing 23 changed files with 1,603 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)
project(jsonschema VERSION 4.3.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(vendor/noa/cmake/noa.cmake)

include_directories(vendor/termcolor/include)
# Options
option(JSONSCHEMA_TESTS "Build the JSON Schema CLI tests" OFF)
option(JSONSCHEMA_TESTS_CI "Build the JSON Schema CLI CI tests" OFF)
Expand Down
1 change: 1 addition & 0 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ hydra https://github.com/sourcemeta/hydra a4a74f3cabd32f2f829f449d67339dac33f991
alterschema https://github.com/sourcemeta/alterschema 92e370ce9c1f0582014b54d43e388ee012dfe13d
jsonbinpack https://github.com/sourcemeta/jsonbinpack d777179441d3c703e1fda1187742541aa26836b5
blaze https://github.com/sourcemeta/blaze 4db8309470369332d3d0658ade9402a37abe418e
termcolor https://github.com/ikalnytskyi/termcolor.git v2.1.0
24 changes: 22 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

#include "command.h"
#include "configure.h"
#ifdef _WIN32
#include <io.h>
#define isatty _isatty
#else
#include <unistd.h>
#endif
#include <termcolor/termcolor.hpp>

constexpr std::string_view USAGE_DETAILS{R"EOF(
Global Options:
Expand Down Expand Up @@ -88,6 +95,13 @@ For more documentation, visit https://github.com/sourcemeta/jsonschema

auto jsonschema_main(const std::string &program, const std::string &command,
const std::span<const std::string> &arguments) -> int {
bool use_colors = true;
if (std::find(arguments.begin(), arguments.end(), "--no-color") !=
arguments.end()) {
use_colors = false;
} else if (!isatty(fileno(stdout))) {
use_colors = false;
}
if (command == "fmt") {
return sourcemeta::jsonschema::cli::fmt(arguments);
} else if (command == "frame") {
Expand All @@ -112,12 +126,18 @@ auto jsonschema_main(const std::string &program, const std::string &command,
return sourcemeta::jsonschema::cli::encode(arguments);
} else if (command == "decode") {
return sourcemeta::jsonschema::cli::decode(arguments);
} else {
}
{
std::cout << "JSON Schema CLI - v"
<< sourcemeta::jsonschema::cli::PROJECT_VERSION << "\n";
std::cout << "Usage: " << std::filesystem::path{program}.filename().string()
<< " <command> [arguments...]\n";
std::cout << USAGE_DETAILS;
if (use_colors) {
std::cout << termcolor::yellow << USAGE_DETAILS << termcolor::reset
<< "\n";
} else {
std::cout << USAGE_DETAILS << "\n";
}
return EXIT_SUCCESS;
}
}
Expand Down
1 change: 1 addition & 0 deletions vendor/termcolor/.mailmap

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

58 changes: 58 additions & 0 deletions vendor/termcolor/CMakeLists.txt

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

31 changes: 31 additions & 0 deletions vendor/termcolor/LICENSE

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

236 changes: 236 additions & 0 deletions vendor/termcolor/README.rst

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

4 changes: 4 additions & 0 deletions vendor/termcolor/cmake/config.cmake.in

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

Binary file added vendor/termcolor/docs/_static/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0b07f2e

Please sign in to comment.