Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
luxe committed Aug 9, 2024
1 parent 2b34266 commit b97825e
Show file tree
Hide file tree
Showing 10 changed files with 453 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ std::string Program_Options::Dir() const{
int Program_Options::Start_At() const{
int data = 0;
if (vm.count("start-at")){
data = vm["start-at"].as<std::string>();
data = vm["start-at"].as<int>();
}

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class
❪iostream❫
❪string❫
❪utility❫
❪regex❫
"code/programs/repo_tools/header_remover/program_options/program_options"
"code/utilities/filesystem/paths/lib"
"code/utilities/streams/filestreams/read_all/lib"
Expand All @@ -15,6 +16,7 @@ class
"code/utilities/types/strings/transformers/other/lib"
"code/utilities/linguistics/computer/header_detection/cpp_header_detector"
❪regex❫
⚞⚟


Expand Down
35 changes: 35 additions & 0 deletions source/code/programs/repo_tools/visibility_adjuster/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package(default_visibility = ["//visibility:public"])

load("//bazel/rules/hcp:hcp.bzl", "hcp")
load("//bazel/rules/hcp:hcp_hdrs_derive.bzl", "hcp_hdrs_derive")
load("//bazel/rules/cpp:object.bzl", "cpp_object")
load("//bazel/rules/cpp:distributable_main.bzl", "distributable_cpp_main")

hcp(
name = "task_executer",
deps = [
"//code/programs/repo_tools/visibility_adjuster/program_options:lib",
"//code/utilities/build/profiler:profile_compilation_timer",
"//code/utilities/filesystem/paths:lib",
"//code/utilities/linguistics/computer/header_detection:cpp_header_detector",
"//code/utilities/program/call/process_spawn:process_spawner",
"//code/utilities/streams/filestreams/read_all:lib",
"//code/utilities/streams/filestreams/write_all:lib",
"//code/utilities/types/strings/observers/other:lib",
"//code/utilities/types/strings/transformers/other:lib",
"//code/utilities/types/strings/transformers/trimming:lib",
"//code/utilities/filesystem/files/getting:lib",
"//code/utilities/types/strings/observers/regex:lib",
],
)

distributable_cpp_main(
name = "visibility_adjuster",
depends = [
],
description = "adjusts visibility on bazel BUILD files",
deps = [
"//code/programs/repo_tools/visibility_adjuster:task_executer",
"//code/programs/repo_tools/visibility_adjuster/program_options:lib",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package(default_visibility = ["//visibility:public"])

load("//bazel/rules/hcp:hcp.bzl", "hcp")
load("//bazel/rules/hcp:hcp_hdrs_derive.bzl", "hcp_hdrs_derive")
load("//bazel/rules/cpp:object.bzl", "cpp_object")

cc_library(
name = "lib",
srcs = glob(["*.cpp"]),
hdrs = glob(["*.hpp"]),
deps = [
"@boost//:program_options",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@

#include "program_options.hpp"
#include <string>
#include <vector>
#include <iostream>
#include <sstream>

//constructor
Program_Options::Program_Options(int const& argc, char** const& argv){
using namespace boost::program_options;

//build all the possible flags and add description.
options_description desc (Get_Options_Description());

//set positional arguments
positional_options_description pod;
pod.add("query", -1);

//build variable map
Build_Variable_Map(argc,argv,desc,pod);

//process immediate options
Process_Immediate_Options(desc);

//validate the mandatory flags
Check_For_Mandatory_Flags_Not_Passed();
}
boost::program_options::options_description Program_Options::Get_Options_Description(void){
using namespace boost::program_options;

//Program Description
options_description desc("adjust bazel visibility across a codebase.");

//Program Flags
desc.add_options()

//these are flag descriptions of that can be passed into the class.
//the code inserted, are the flags added by the user through the
//program_options_maker flag interface
("run_dir",value<std::string>(),"where to run the analysis")
("file",value<std::string>(),"the file to remove headers from")
("dir",value<std::string>(),"the dir to remove headers from")
("target",value<std::string>(),"target to check with")
("commands",value<std::vector<std::string>>(),"commands to check with")
("start-at",value<int>(),"where to start in the file iteration")
("find",value<std::string>(),"regex to match on")
("replace",value<std::string>(),"what to replace the regex match with")

//+----------------------------------------------------------+
//| Obligatory |
//+----------------------------------------------------------+
("help,h","produce this help message")
("version,v","display version")
;

return desc;
}
std::string Program_Options::Get_Help_Message(){
std::stringstream ss;
ss << Get_Options_Description();
return ss.str();
}
void Program_Options::Build_Variable_Map(int const& argc, char** const& argv, boost::program_options::options_description const& desc, boost::program_options::positional_options_description const& pod){
using namespace boost::program_options;

//store user flag data. crash elegantly if they pass incorrect flags.
try{
store(command_line_parser(argc, argv).options(desc).positional(pod).run(), vm);
notify(vm);
}
catch(error& e){
std::cerr << "ERROR: " << e.what() << std::endl;
std::cerr << desc << std::endl;
exit(EXIT_FAILURE);
}

return;
}
void Program_Options::Process_Immediate_Options( boost::program_options::options_description const& desc){

//do not continue the program if the user wanted to see the version or help data
if (vm.count("version")){
std::cout << "\nThis is version " << "1" << " of noogle.\n\n";
exit(EXIT_SUCCESS);
}
else if (vm.count("help")){
std::cout << '\n' << desc << '\n';
exit(EXIT_SUCCESS);
}

return;
}

void Program_Options::Check_For_Mandatory_Flags_Not_Passed(){
std::vector<std::string> flags_not_passed;
//if(!vm.count("input_files")){flags_not_passed.push_back("input_files");}
//if(!vm.count("exporter")){flags_not_passed.push_back("exporter");}
//if(!vm.count("language")){flags_not_passed.push_back("language");}

if (!flags_not_passed.empty()){
std::cerr << "you need to pass the following flags still:\n";
for (auto it: flags_not_passed){
std::cerr << '\t' << it << '\n';
}
exit(EXIT_FAILURE);
}
return;
}
std::string Program_Options::Run_Dir() const{
std::string data;
if (vm.count("run_dir")){
data = vm["run_dir"].as<std::string>();
}

return data;
}
std::string Program_Options::File() const{
std::string data;
if (vm.count("file")){
data = vm["file"].as<std::string>();
}

return data;
}
std::string Program_Options::Target() const{
std::string data;
if (vm.count("target")){
data = vm["target"].as<std::string>();
}

return data;
}
std::string Program_Options::Dir() const{
std::string data;
if (vm.count("dir")){
data = vm["dir"].as<std::string>();
}

return data;
}

int Program_Options::Start_At() const{
int data = 0;
if (vm.count("start-at")){
data = vm["start-at"].as<int>();
}

return data;
}

std::string Program_Options::Find() const{
std::string data;
if (vm.count("find")){
data = vm["find"].as<std::string>();
}
return data;
}
std::string Program_Options::Replace() const{
std::string data;
if (vm.count("replace")){
data = vm["replace"].as<std::string>();
}
return data;
}

std::vector<std::string> Program_Options::Commands() const{
std::vector<std::string> data;
if (vm.count("commands")){
data = vm["commands"].as<std::vector<std::string>>();
}

return data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

//Boost Libraries
#include "boost/program_options.hpp"

class Program_Options {

public:

//Constructor
explicit Program_Options(int const& argc, char** const& argv);

//These are functions for the client who uses the Program Options object.
//They include all of the functions passed to the program_options_maker.
//The options "help" and "version", do not need to be implemented by the user.
//The "help" and "version" flags are always added automatically unless specified not to be.
//+----------------------------------------------------------+
//| USER FLAGS |
//+----------------------------------------------------------+
std::string Run_Dir() const;
std::string File() const;
std::string Dir() const;
std::string Target() const;
std::vector<std::string> Commands() const;
int Start_At() const;
std::string Find() const;
std::string Replace() const;


std::string Get_Help_Message();


private:

//functions used to parse, store, verify, and immediately process SOME of the flags.
//other verification of flag data is passed on as a responsibility of the Program_Options_Checker
auto Get_Options_Description() -> boost::program_options::options_description;
auto Build_Variable_Map(int const& argc, char** const& argv, boost::program_options::options_description const& desc, boost::program_options::positional_options_description const& pod) -> void;
auto Process_Immediate_Options(boost::program_options::options_description const& desc) -> void;
auto Check_For_Mandatory_Flags_Not_Passed() -> void;

//Data Members
//the variables map, holds all of the flag data passed in through the constructor.
boost::program_options::variables_map vm;
};
Loading

0 comments on commit b97825e

Please sign in to comment.