洞察探索如何利用兼容微信生态的小程序容器,实现跨平台开发,助力金融和车联网行业的数字化转型。
626
2022-10-31
一个易于使用的C++库,用于构建强大的控制台应用程序
Console Component
An easy to use component for building powerful console applications written in C++.
Console ComponentPreviewInstallUsageBuildTargetMotiviationContribution
Preview
Install:
Create Project:
Usage:
Install
The easiest way to install is to use the vscode extension:
MarketplaceRepository
Alternative this could also be achieved in few manual steps:
First let's download the CPM script
mkdir -p cmake && wget -O cmake/CPM.cmake https://raw.githubusercontent.com/TheLartians/CPM/master/cmake/CPM.cmake
Then include this script in your CMake file:
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)project(my_cli CXX)# Add The CPM Scriptinclude(cmake/CPM.cmake)# Add The console-componentCPMAddPackage( NAME console GITHUB_REPOSITORY edenreich/console-component VERSION 1.0.2 OPTIONS "WITH_TESTS Off")
Create a directory called commands, there you would store all your command objects (see usage on how to create a command). Lastly link your executable with the console-component like this: target_link_libraries(${PROJECT_NAME} console)
If you having trouble setting this up, take a look on the a examples first.
Usage
Create a command definition file:
// commands/copy_files.h#pragma once#include
Create a command implemention file:
// commands/copy_files.cpp#include "copy_files.h"/** * Retrieve the name of the command. * * @return std::string */std::string CopyFiles::getName(){ return "copy:files";}/** * Retrieve the description of the command. * * @return std::string */std::string CopyFiles::getDescription(){ return "copy files from
Create the application and add the command:
// main.cpp#include
Build
Run cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . --config Release --target install -- -j4
After building the project all distributed files should be located in build/dist.
Target
This project targets Linux, Windows and macOS
Motiviation
Often I find myself have to write the same code over and over again, So I've decided to dedicate my time to build a console application in an OOP way. After all, all it is needed is a CPP and HEADER file per command. Having dedicated class / object per command makes it easier to maintain.
Because it is statically linked library I have avoided including external libraries and kept it as simple as possible.
Contribution
If you find this project interesting or have any suggestions, feel free to send a pull request. I will be more than happy to review it.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~