2019-01-03 16:22:34 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2019-01-07 15:48:27 +00:00
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/strings/string_util.h"
|
|
|
|
#include "services/network/public/cpp/network_switches.h"
|
2021-06-03 08:05:04 +00:00
|
|
|
#include "shell/common/gin_converters/base_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
2019-01-03 16:22:34 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool HasSwitch(const std::string& name) {
|
|
|
|
return base::CommandLine::ForCurrentProcess()->HasSwitch(name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
base::CommandLine::StringType GetSwitchValue(const std::string& name) {
|
|
|
|
return base::CommandLine::ForCurrentProcess()->GetSwitchValueNative(
|
|
|
|
name.c_str());
|
|
|
|
}
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
void AppendSwitch(const std::string& switch_string,
|
|
|
|
gin_helper::Arguments* args) {
|
2019-01-07 15:48:27 +00:00
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
if (base::EndsWith(switch_string, "-path",
|
|
|
|
base::CompareCase::INSENSITIVE_ASCII) ||
|
|
|
|
switch_string == network::switches::kLogNetLog) {
|
|
|
|
base::FilePath path;
|
|
|
|
args->GetNext(&path);
|
|
|
|
command_line->AppendSwitchPath(switch_string, path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::CommandLine::StringType value;
|
|
|
|
if (args->GetNext(&value))
|
|
|
|
command_line->AppendSwitchNative(switch_string, value);
|
|
|
|
else
|
|
|
|
command_line->AppendSwitch(switch_string);
|
|
|
|
}
|
|
|
|
|
2021-06-03 08:05:04 +00:00
|
|
|
void AppendArg(const std::string& arg) {
|
|
|
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
|
|
|
|
command_line->AppendArg(arg);
|
|
|
|
}
|
|
|
|
|
2019-01-03 16:22:34 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2019-10-31 07:56:00 +00:00
|
|
|
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
2019-01-03 16:22:34 +00:00
|
|
|
dict.SetMethod("hasSwitch", &HasSwitch);
|
|
|
|
dict.SetMethod("getSwitchValue", &GetSwitchValue);
|
2019-01-07 15:48:27 +00:00
|
|
|
dict.SetMethod("appendSwitch", &AppendSwitch);
|
2021-06-03 08:05:04 +00:00
|
|
|
dict.SetMethod("appendArgument", &AppendArg);
|
2019-01-03 16:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-02-14 11:25:39 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_common_command_line, Initialize)
|