summaryrefslogtreecommitdiffhomepage
path: root/tooling/mkfs.h
blob: 7180b17909e22860361e57cc80626e43ea263db9 (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
/* -------------------------------------------

  Copyright (C) 2025, Amlal El Mahrouss, all rights reserved.

------------------------------------------- */

#pragma once

#include <tooling/rang.h>
#include <iostream>
#include <string>

/// @internal
namespace mkfs {
/// @brief Helper function to get the option value from command line arguments.
template <typename CharType>
inline std::basic_string<CharType> get_option(const std::basic_string<CharType>& args,
                                              const std::basic_string<CharType>& option) {
  size_t pos = args.find(option + CharType('='));

  if (pos != std::string::npos) {
    size_t start = pos + option.length() + 1;
    size_t end   = args.find(' ', start);
    return args.substr(start, end - start);
  }

  return std::basic_string<CharType>{};
}

inline auto console_out() -> std::ostream& {
  std::ostream& conout = std::cout;
  conout << rang::fg::red << "mkfs: " << rang::style::reset;

  return conout;
}
}  // namespace mkfs