MCPcopy Create free account
hub / github.com/duckdb/duckdb / RunShell

Function RunShell

tools/shell/shell.cpp:3075–3284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3073}
3074
3075int RunShell(int argc, const char **argv) {
3076 int rc = 0;
3077 vector<string> extra_commands;
3078
3079 auto &data = ShellState::Get();
3080 data.out = stdout;
3081
3082 setBinaryMode(stdin, 0);
3083 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
3084 data.stdin_is_interactive = isatty(0);
3085 data.stdout_is_console = isatty(1);
3086 data.stderr_is_console = isatty(2);
3087
3088 data.Initialize();
3089
3090 /* On Windows, we must translate command-line arguments into UTF-8.
3091 */
3092
3093 assert(argc >= 1 && argv && argv[0]);
3094 data.program_name = argv[0];
3095
3096 /* Make sure we have a valid signal handler early, before anything
3097 ** else is done.
3098 */
3099#ifdef SIGINT
3100 signal(SIGINT, InterruptHandler);
3101#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
3102 SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
3103#endif
3104
3105 /* Do an initial pass through the command-line argument to locate
3106 ** the name of the database file, the name of the initialization file,
3107 ** the size of the alternative malloc heap,
3108 ** and the first command to execute.
3109 */
3110 vector<CommandLineCall> command_line_calls;
3111 for (int i = 1; i < argc; i++) {
3112 auto z = argv[i];
3113 if (z[0] != '-') {
3114 if (data.zDbFilename.empty()) {
3115 data.zDbFilename = z;
3116 } else {
3117 /* Excesss arguments are interpreted as SQL (or dot-commands) and
3118 ** mean that nothing is read from stdin */
3119 data.readStdin = false;
3120 data.stdin_is_interactive = false;
3121 extra_commands.emplace_back(z);
3122 }
3123 continue;
3124 }
3125 z++;
3126 if (z[0] == '-') {
3127 // allow for double dashes, i.e. --init and -init are both valid
3128 z++;
3129 }
3130
3131 string error_msg;
3132 auto command_line_option = data.FindCommandLineOption(z, error_msg);

Callers 1

wmainFunction · 0.85

Calls 15

setBinaryModeFunction · 0.85
ContainsFunction · 0.85
GetHomeDirectoryFunction · 0.85
FindCommandLineOptionMethod · 0.80
PrintDatabaseErrorMethod · 0.80
OpenDBMethod · 0.80
ProcessDuckDBRCMethod · 0.80
c_strMethod · 0.80
DetectDarkLightModeMethod · 0.80
DoMetaCommandMethod · 0.80
ShellLoadHistoryMethod · 0.80

Tested by

no test coverage detected