aboutsummaryrefslogtreecommitdiff
path: root/bpkg/manifest-utility.cxx
blob: 76c1957d37caff4a79a6840d65809ac02dc7e591 (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
// file      : bpkg/manifest-utility.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <bpkg/manifest-utility>

#include <stdexcept> // invalid_argument

#include <bpkg/diagnostics>

using namespace std;

namespace bpkg
{
  version
  parse_version (const char* s)
  try
  {
    return version (s);
  }
  catch (const invalid_argument& e)
  {
    error << "invalid package version '" << s << "': " << e.what ();
    throw failed ();
  }

  repository_location
  parse_location (const char* s)
  try
  {
    repository_location rl (s, repository_location ());

    if (rl.relative ()) // Throws if the location is empty.
      rl = repository_location (
        dir_path (s).complete ().normalize ().string ());

    return rl;
  }
  catch (const invalid_argument& e)
  {
    error << "invalid repository location '" << s << "': " << e.what ();
    throw failed ();
  }
}