StartupOptions.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Collections.Generic;
  2. using CommandLine;
  3. using Emby.Server.Implementations;
  4. using static MediaBrowser.Controller.Extensions.ConfigurationExtensions;
  5. namespace Jellyfin.Server
  6. {
  7. /// <summary>
  8. /// Class used by CommandLine package when parsing the command line arguments.
  9. /// </summary>
  10. public class StartupOptions : IStartupOptions
  11. {
  12. /// <summary>
  13. /// Gets or sets the path to the data directory.
  14. /// </summary>
  15. /// <value>The path to the data directory.</value>
  16. [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (database files, etc.).")]
  17. public string? DataDir { get; set; }
  18. /// <summary>
  19. /// Gets or sets a value indicating whether the server should not host the web client.
  20. /// </summary>
  21. [Option("nowebclient", Required = false, HelpText = "Indicates that the web server should not host the web client.")]
  22. public bool NoWebClient { get; set; }
  23. /// <summary>
  24. /// Gets or sets the path to the web directory.
  25. /// </summary>
  26. /// <value>The path to the web directory.</value>
  27. [Option('w', "webdir", Required = false, HelpText = "Path to the Jellyfin web UI resources.")]
  28. public string? WebDir { get; set; }
  29. /// <summary>
  30. /// Gets or sets the path to the cache directory.
  31. /// </summary>
  32. /// <value>The path to the cache directory.</value>
  33. [Option('C', "cachedir", Required = false, HelpText = "Path to use for caching.")]
  34. public string? CacheDir { get; set; }
  35. /// <summary>
  36. /// Gets or sets the path to the config directory.
  37. /// </summary>
  38. /// <value>The path to the config directory.</value>
  39. [Option('c', "configdir", Required = false, HelpText = "Path to use for configuration data (user settings and pictures).")]
  40. public string? ConfigDir { get; set; }
  41. /// <summary>
  42. /// Gets or sets the path to the log directory.
  43. /// </summary>
  44. /// <value>The path to the log directory.</value>
  45. [Option('l', "logdir", Required = false, HelpText = "Path to use for writing log files.")]
  46. public string? LogDir { get; set; }
  47. /// <inheritdoc />
  48. [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg executable to use in place of default found in PATH.")]
  49. public string? FFmpegPath { get; set; }
  50. /// <inheritdoc />
  51. [Option("service", Required = false, HelpText = "Run as headless service.")]
  52. public bool IsService { get; set; }
  53. /// <inheritdoc />
  54. [Option("package-name", Required = false, HelpText = "Used when packaging Jellyfin (example, synology).")]
  55. public string? PackageName { get; set; }
  56. /// <inheritdoc />
  57. [Option("published-server-url", Required = false, HelpText = "Jellyfin Server URL to publish via auto discover process")]
  58. public string? PublishedServerUrl { get; set; }
  59. /// <summary>
  60. /// Gets or sets a value indicating whether the server should not detect network status change.
  61. /// </summary>
  62. [Option("nonetchange", Required = false, HelpText = "Indicates that the server should not detect network status change.")]
  63. public bool NoDetectNetworkChange { get; set; }
  64. /// <summary>
  65. /// Gets or sets the path to an jellyfin backup archive to restore the application to.
  66. /// </summary>
  67. [Option("restore-archive", Required = false, HelpText = "Path to a Jellyfin backup archive to restore from")]
  68. public string? RestoreArchive { get; set; }
  69. /// <summary>
  70. /// Gets the command line options as a dictionary that can be used in the .NET configuration system.
  71. /// </summary>
  72. /// <returns>The configuration dictionary.</returns>
  73. public Dictionary<string, string?> ConvertToConfig()
  74. {
  75. var config = new Dictionary<string, string?>();
  76. if (NoWebClient)
  77. {
  78. config.Add(HostWebClientKey, bool.FalseString);
  79. }
  80. if (PublishedServerUrl is not null)
  81. {
  82. config.Add(AddressOverrideKey, PublishedServerUrl);
  83. }
  84. if (FFmpegPath is not null)
  85. {
  86. config.Add(FfmpegPathKey, FFmpegPath);
  87. }
  88. if (NoDetectNetworkChange)
  89. {
  90. config.Add(DetectNetworkChangeKey, bool.FalseString);
  91. }
  92. return config;
  93. }
  94. }
  95. }