Skip to content

Commit b97825e

Browse files
committed
updates
1 parent 2b34266 commit b97825e

File tree

10 files changed

+453
-1
lines changed

10 files changed

+453
-1
lines changed

source/code/programs/repo_tools/header_remover/program_options/program_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ std::string Program_Options::Dir() const{
140140
int Program_Options::Start_At() const{
141141
int data = 0;
142142
if (vm.count("start-at")){
143-
data = vm["start-at"].as<std::string>();
143+
data = vm["start-at"].as<int>();
144144
}
145145

146146
return data;

source/code/programs/repo_tools/header_remover/task_executer.hcp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class
22
❪iostream❫
33
❪string❫
44
❪utility❫
5+
❪regex❫
56
❪"code/programs/repo_tools/header_remover/program_options/program_options"❫
67
❪"code/utilities/filesystem/paths/lib"❫
78
❪"code/utilities/streams/filestreams/read_all/lib"❫
@@ -15,6 +16,7 @@ class
1516
❪"code/utilities/types/strings/transformers/other/lib"❫
1617
❪"code/utilities/linguistics/computer/header_detection/cpp_header_detector"❫
1718
19+
❪regex❫
1820
⚞⚟
1921

2022

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//bazel/rules/hcp:hcp.bzl", "hcp")
4+
load("//bazel/rules/hcp:hcp_hdrs_derive.bzl", "hcp_hdrs_derive")
5+
load("//bazel/rules/cpp:object.bzl", "cpp_object")
6+
load("//bazel/rules/cpp:distributable_main.bzl", "distributable_cpp_main")
7+
8+
hcp(
9+
name = "task_executer",
10+
deps = [
11+
"//code/programs/repo_tools/visibility_adjuster/program_options:lib",
12+
"//code/utilities/build/profiler:profile_compilation_timer",
13+
"//code/utilities/filesystem/paths:lib",
14+
"//code/utilities/linguistics/computer/header_detection:cpp_header_detector",
15+
"//code/utilities/program/call/process_spawn:process_spawner",
16+
"//code/utilities/streams/filestreams/read_all:lib",
17+
"//code/utilities/streams/filestreams/write_all:lib",
18+
"//code/utilities/types/strings/observers/other:lib",
19+
"//code/utilities/types/strings/transformers/other:lib",
20+
"//code/utilities/types/strings/transformers/trimming:lib",
21+
"//code/utilities/filesystem/files/getting:lib",
22+
"//code/utilities/types/strings/observers/regex:lib",
23+
],
24+
)
25+
26+
distributable_cpp_main(
27+
name = "visibility_adjuster",
28+
depends = [
29+
],
30+
description = "adjusts visibility on bazel BUILD files",
31+
deps = [
32+
"//code/programs/repo_tools/visibility_adjuster:task_executer",
33+
"//code/programs/repo_tools/visibility_adjuster/program_options:lib",
34+
],
35+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//bazel/rules/hcp:hcp.bzl", "hcp")
4+
load("//bazel/rules/hcp:hcp_hdrs_derive.bzl", "hcp_hdrs_derive")
5+
load("//bazel/rules/cpp:object.bzl", "cpp_object")
6+
7+
cc_library(
8+
name = "lib",
9+
srcs = glob(["*.cpp"]),
10+
hdrs = glob(["*.hpp"]),
11+
deps = [
12+
"@boost//:program_options",
13+
],
14+
)
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
2+
#include "program_options.hpp"
3+
#include <string>
4+
#include <vector>
5+
#include <iostream>
6+
#include <sstream>
7+
8+
//constructor
9+
Program_Options::Program_Options(int const& argc, char** const& argv){
10+
using namespace boost::program_options;
11+
12+
//build all the possible flags and add description.
13+
options_description desc (Get_Options_Description());
14+
15+
//set positional arguments
16+
positional_options_description pod;
17+
pod.add("query", -1);
18+
19+
//build variable map
20+
Build_Variable_Map(argc,argv,desc,pod);
21+
22+
//process immediate options
23+
Process_Immediate_Options(desc);
24+
25+
//validate the mandatory flags
26+
Check_For_Mandatory_Flags_Not_Passed();
27+
}
28+
boost::program_options::options_description Program_Options::Get_Options_Description(void){
29+
using namespace boost::program_options;
30+
31+
//Program Description
32+
options_description desc("adjust bazel visibility across a codebase.");
33+
34+
//Program Flags
35+
desc.add_options()
36+
37+
//these are flag descriptions of that can be passed into the class.
38+
//the code inserted, are the flags added by the user through the
39+
//program_options_maker flag interface
40+
("run_dir",value<std::string>(),"where to run the analysis")
41+
("file",value<std::string>(),"the file to remove headers from")
42+
("dir",value<std::string>(),"the dir to remove headers from")
43+
("target",value<std::string>(),"target to check with")
44+
("commands",value<std::vector<std::string>>(),"commands to check with")
45+
("start-at",value<int>(),"where to start in the file iteration")
46+
("find",value<std::string>(),"regex to match on")
47+
("replace",value<std::string>(),"what to replace the regex match with")
48+
49+
//+----------------------------------------------------------+
50+
//| Obligatory |
51+
//+----------------------------------------------------------+
52+
("help,h","produce this help message")
53+
("version,v","display version")
54+
;
55+
56+
return desc;
57+
}
58+
std::string Program_Options::Get_Help_Message(){
59+
std::stringstream ss;
60+
ss << Get_Options_Description();
61+
return ss.str();
62+
}
63+
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){
64+
using namespace boost::program_options;
65+
66+
//store user flag data. crash elegantly if they pass incorrect flags.
67+
try{
68+
store(command_line_parser(argc, argv).options(desc).positional(pod).run(), vm);
69+
notify(vm);
70+
}
71+
catch(error& e){
72+
std::cerr << "ERROR: " << e.what() << std::endl;
73+
std::cerr << desc << std::endl;
74+
exit(EXIT_FAILURE);
75+
}
76+
77+
return;
78+
}
79+
void Program_Options::Process_Immediate_Options( boost::program_options::options_description const& desc){
80+
81+
//do not continue the program if the user wanted to see the version or help data
82+
if (vm.count("version")){
83+
std::cout << "\nThis is version " << "1" << " of noogle.\n\n";
84+
exit(EXIT_SUCCESS);
85+
}
86+
else if (vm.count("help")){
87+
std::cout << '\n' << desc << '\n';
88+
exit(EXIT_SUCCESS);
89+
}
90+
91+
return;
92+
}
93+
94+
void Program_Options::Check_For_Mandatory_Flags_Not_Passed(){
95+
std::vector<std::string> flags_not_passed;
96+
//if(!vm.count("input_files")){flags_not_passed.push_back("input_files");}
97+
//if(!vm.count("exporter")){flags_not_passed.push_back("exporter");}
98+
//if(!vm.count("language")){flags_not_passed.push_back("language");}
99+
100+
if (!flags_not_passed.empty()){
101+
std::cerr << "you need to pass the following flags still:\n";
102+
for (auto it: flags_not_passed){
103+
std::cerr << '\t' << it << '\n';
104+
}
105+
exit(EXIT_FAILURE);
106+
}
107+
return;
108+
}
109+
std::string Program_Options::Run_Dir() const{
110+
std::string data;
111+
if (vm.count("run_dir")){
112+
data = vm["run_dir"].as<std::string>();
113+
}
114+
115+
return data;
116+
}
117+
std::string Program_Options::File() const{
118+
std::string data;
119+
if (vm.count("file")){
120+
data = vm["file"].as<std::string>();
121+
}
122+
123+
return data;
124+
}
125+
std::string Program_Options::Target() const{
126+
std::string data;
127+
if (vm.count("target")){
128+
data = vm["target"].as<std::string>();
129+
}
130+
131+
return data;
132+
}
133+
std::string Program_Options::Dir() const{
134+
std::string data;
135+
if (vm.count("dir")){
136+
data = vm["dir"].as<std::string>();
137+
}
138+
139+
return data;
140+
}
141+
142+
int Program_Options::Start_At() const{
143+
int data = 0;
144+
if (vm.count("start-at")){
145+
data = vm["start-at"].as<int>();
146+
}
147+
148+
return data;
149+
}
150+
151+
std::string Program_Options::Find() const{
152+
std::string data;
153+
if (vm.count("find")){
154+
data = vm["find"].as<std::string>();
155+
}
156+
return data;
157+
}
158+
std::string Program_Options::Replace() const{
159+
std::string data;
160+
if (vm.count("replace")){
161+
data = vm["replace"].as<std::string>();
162+
}
163+
return data;
164+
}
165+
166+
std::vector<std::string> Program_Options::Commands() const{
167+
std::vector<std::string> data;
168+
if (vm.count("commands")){
169+
data = vm["commands"].as<std::vector<std::string>>();
170+
}
171+
172+
return data;
173+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
3+
//Boost Libraries
4+
#include "boost/program_options.hpp"
5+
6+
class Program_Options {
7+
8+
public:
9+
10+
//Constructor
11+
explicit Program_Options(int const& argc, char** const& argv);
12+
13+
//These are functions for the client who uses the Program Options object.
14+
//They include all of the functions passed to the program_options_maker.
15+
//The options "help" and "version", do not need to be implemented by the user.
16+
//The "help" and "version" flags are always added automatically unless specified not to be.
17+
//+----------------------------------------------------------+
18+
//| USER FLAGS |
19+
//+----------------------------------------------------------+
20+
std::string Run_Dir() const;
21+
std::string File() const;
22+
std::string Dir() const;
23+
std::string Target() const;
24+
std::vector<std::string> Commands() const;
25+
int Start_At() const;
26+
std::string Find() const;
27+
std::string Replace() const;
28+
29+
30+
std::string Get_Help_Message();
31+
32+
33+
private:
34+
35+
//functions used to parse, store, verify, and immediately process SOME of the flags.
36+
//other verification of flag data is passed on as a responsibility of the Program_Options_Checker
37+
auto Get_Options_Description() -> boost::program_options::options_description;
38+
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;
39+
auto Process_Immediate_Options(boost::program_options::options_description const& desc) -> void;
40+
auto Check_For_Mandatory_Flags_Not_Passed() -> void;
41+
42+
//Data Members
43+
//the variables map, holds all of the flag data passed in through the constructor.
44+
boost::program_options::variables_map vm;
45+
};

0 commit comments

Comments
 (0)