logic: improve usability of shallow indexing ui (#823)

* added "--shallow" command line option to request shallow indexing
* modified behavior of Sourcetrail to always perform a deep index if not explicitly specified differently by the user
This commit is contained in:
Malte Langkabel
2019-12-03 18:26:02 +01:00
committed by GitHub
parent 00bf7ebda6
commit fa6dd6c9e1
10 changed files with 52 additions and 39 deletions
@@ -17,31 +17,27 @@ namespace po = boost::program_options;
namespace commandline
{
CommandLineParser::CommandLineParser(const std::string& version): m_version(version)
{
setup();
}
CommandLineParser::~CommandLineParser() {}
void CommandLineParser::setup()
{
po::options_description options("Options");
options.add_options()("help,h", "Print this help message")(
"version,v", "Version of Sourcetrail")(
"project-file", po::value<std::string>(), "Open Sourcetrail with this project (.srctrlprj)");
options.add_options()
("help,h", "Print this help message")
("version,v", "Version of Sourcetrail")
("project-file", po::value<std::string>(), "Open Sourcetrail with this project (.srctrlprj)");
m_options.add(options);
m_positional.add("project-file", 1);
addCommand(std::make_unique<commandline::CommandlineCommandConfig>(this));
addCommand(std::make_unique<commandline::CommandlineCommandIndex>(this));
m_commands.push_back(std::make_unique<commandline::CommandlineCommandConfig>(this));
m_commands.push_back(std::make_unique<commandline::CommandlineCommandIndex>(this));
for (auto& command: m_commands)
for (auto& command : m_commands)
{
command->setup();
}
}
CommandLineParser::~CommandLineParser() {}
void CommandLineParser::preparse(int argc, char** argv)
{
std::vector<std::string> args;
@@ -148,11 +144,6 @@ void CommandLineParser::setProjectFile(const FilePath& filepath)
processProjectfile();
}
void CommandLineParser::addCommand(std::unique_ptr<CommandlineCommand> command)
{
m_commands.push_back(std::move(command));
}
void CommandLineParser::printHelp() const
{
std::cout << "Usage:\n Sourcetrail [command] [option...] [positional arguments]\n\n";
@@ -240,6 +231,11 @@ void CommandLineParser::incompleteRefresh()
m_refreshMode = REFRESH_UPDATED_AND_INCOMPLETE_FILES;
}
void CommandLineParser::setShallowIndexingRequested(bool enabled)
{
m_shallowIndexingRequested = enabled;
}
const FilePath& CommandLineParser::getProjectFilePath() const
{
return m_projectFile;
@@ -250,4 +246,9 @@ RefreshMode CommandLineParser::getRefreshMode() const
return m_refreshMode;
}
bool CommandLineParser::getShallowIndexingRequested() const
{
return m_shallowIndexingRequested;
}
} // namespace commandline
@@ -22,8 +22,6 @@ public:
CommandLineParser(const std::string& version);
~CommandLineParser();
void setup();
void preparse(int argc, char** argv);
void preparse(std::vector<std::string>& args);
void parse();
@@ -36,14 +34,15 @@ public:
void fullRefresh();
void incompleteRefresh();
void setShallowIndexingRequested(bool enabled = true);
const FilePath& getProjectFilePath() const;
void setProjectFile(const FilePath& filepath);
RefreshMode getRefreshMode() const;
bool getShallowIndexingRequested() const;
private:
void addCommand(std::unique_ptr<CommandlineCommand> command);
void processProjectfile();
void printHelp() const;
@@ -56,6 +55,7 @@ private:
const std::string m_version;
FilePath m_projectFile;
RefreshMode m_refreshMode = REFRESH_UPDATED_FILES;
bool m_shallowIndexingRequested = false;
bool m_quit = false;
bool m_withoutGUI = false;
@@ -19,10 +19,12 @@ CommandlineCommandIndex::~CommandlineCommandIndex() {}
void CommandlineCommandIndex::setup()
{
po::options_description options("Config Options");
options.add_options()("help,h", "Print this help message")(
"incomplete,i", "Also reindex incomplete files (files with errors)")(
"full,f", "Index full project (omit to only index new/changed files)")(
"project-file", po::value<std::string>(), "Project file to index (.srctrlprj)");
options.add_options()
("help,h", "Print this help message")
("incomplete,i", "Also reindex incomplete files (files with errors)")
("full,f", "Index full project (omit to only index new/changed files)")
("shallow,s", "Build a shallow index is supported by the project")
("project-file", po::value<std::string>(), "Project file to index (.srctrlprj)");
m_options.add(options);
m_positional.add("project-file", 1);
@@ -61,6 +63,11 @@ CommandlineCommand::ReturnStatus CommandlineCommandIndex::parse(std::vector<std:
m_parser->incompleteRefresh();
}
if (vm.count("shallow"))
{
m_parser->setShallowIndexingRequested();
}
if (vm.count("project-file"))
{
m_parser->setProjectFile(FilePath(vm["project-file"].as<std::string>()));
@@ -10,10 +10,11 @@ class MessageLoadProject: public Message<MessageLoadProject>
{
public:
MessageLoadProject(
const FilePath& filePath, bool settingsChanged = false, RefreshMode refreshMode = REFRESH_NONE)
const FilePath& filePath, bool settingsChanged = false, RefreshMode refreshMode = REFRESH_NONE, bool shallowIndexingRequested = false)
: projectSettingsFilePath(filePath)
, settingsChanged(settingsChanged)
, refreshMode(refreshMode)
, shallowIndexingRequested(shallowIndexingRequested)
{
}
@@ -32,6 +33,7 @@ public:
const FilePath projectSettingsFilePath;
const bool settingsChanged;
const RefreshMode refreshMode;
const bool shallowIndexingRequested;
};
#endif // MESSAGE_LOAD_PROJECT_H