summaryrefslogtreecommitdiffstats
path: root/xbmc/platform/linux/AppParamParserLinux.cpp
blob: 3a1adf9d5eec70f2abdffe29371d0e148d0f96f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 *  Copyright (C) 2005-2021 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "AppParamParserLinux.h"

#include "CompileInfo.h"
#include "application/AppParams.h"
#include "utils/StringUtils.h"

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

namespace
{
std::vector<std::string> availableWindowSystems = CCompileInfo::GetAvailableWindowSystems();
std::array<std::string, 1> availableLogTargets = {"console"};

constexpr const char* windowingText =
    R"""(
Selected window system not available: {}
    Available window systems: {}
)""";

constexpr const char* loggingText =
    R"""(
Selected logging target not available: {}
    Available log targest: {}
)""";

constexpr const char* helpText =
    R"""(
Linux Specific Arguments:
  --windowing=<system>  Select which windowing method to use.
                          Available window systems are: {}
  --logging=<target>    Select which log target to use (log file will always be used in conjunction).
                          Available log targets are: {}
)""";


} // namespace

CAppParamParserLinux::CAppParamParserLinux() : CAppParamParser()
{
}

CAppParamParserLinux::~CAppParamParserLinux() = default;

void CAppParamParserLinux::ParseArg(const std::string& arg)
{
  CAppParamParser::ParseArg(arg);

  if (arg.substr(0, 12) == "--windowing=")
  {
    if (std::find(availableWindowSystems.begin(), availableWindowSystems.end(), arg.substr(12)) !=
        availableWindowSystems.end())
      GetAppParams()->SetWindowing(arg.substr(12));
    else
    {
      std::cout << StringUtils::Format(windowingText, arg.substr(12),
                                       StringUtils::Join(availableWindowSystems, ", "));
      exit(0);
    }
  }
  else if (arg.substr(0, 10) == "--logging=")
  {
    if (std::find(availableLogTargets.begin(), availableLogTargets.end(), arg.substr(10)) !=
        availableLogTargets.end())
    {
      GetAppParams()->SetLogTarget(arg.substr(10));
    }
    else
    {
      std::cout << StringUtils::Format(loggingText, arg.substr(10),
                                       StringUtils::Join(availableLogTargets, ", "));
      exit(0);
    }
  }
}

void CAppParamParserLinux::DisplayHelp()
{
  CAppParamParser::DisplayHelp();

  std::cout << StringUtils::Format(helpText, StringUtils::Join(availableWindowSystems, ", "),
                                   StringUtils::Join(availableLogTargets, ", "));
}