1#!/bin/bash
2# Copyright (c) 2023 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16
17function install_pytest() {
18    if ! command -v pytest &> /dev/null; then
19        echo "Installing pytest..."
20        python -m pip install pytest "$@"
21    else
22        echo "pytest is already installed."
23    fi
24}
25
26function install_pytest_html() {
27    if ! pip show pytest-html &> /dev/null; then
28      echo "Installing pytest-html..."
29      python -m pip install pytest-html "$@"
30    else
31        echo "pytest-html is already installed."
32    fi
33}
34
35function install_pytest_metadata() {
36    if ! pip show pytest-metadata &> /dev/null; then
37        echo "Installing pytest-metadata..."
38        python -m pip install pytest-metadata "$@"
39    else
40        echo "pytest-metadata is already installed."
41    fi
42}
43
44function install_py() {
45    if ! pip show py &> /dev/null; then
46        echo "Installing py..."
47        python -m pip install py "$@"
48    else
49        echo "py is already installed."
50    fi
51}
52
53function install() {
54    install_pytest "$@"
55    install_pytest_html "$@"
56    install_pytest_metadata "$@"
57    install_py "$@"
58}
59
60function start() {
61    if [[ $# -eq 2 && $1 == "-i" ]]; then
62        install "$@"
63    elif [[ $# -eq 0 ]]; then
64        install "$@"
65    else
66        echo "args wrong"
67    fi
68}
69
70start "$@"
71