UNPKG

@ohos/hpm-cli

Version:

CLI for HarmonyOS package manager

78 lines (76 loc) 3.64 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.config = void 0; var _rcParser = _interopRequireDefault(require("../core/rc-parser")); var _i18n = _interopRequireWildcard(require("../i18n")); var _constant = require("../constant/constant"); var _crypto = _interopRequireDefault(require("../core/crypto")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } /* * Copyright (c) 2020-2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var config = exports.config = function config(options, _ref) { var args = _ref.args; var actionName = args && args[0]; var rcParser = _rcParser["default"].fromPath(_constant.DEFAULT_CONFIG_FILE); var key = args[1]; var value = args[2]; switch (actionName) { case 'set': if (args.length !== 3) { throw (0, _i18n.getI18nMessage)('config.setFormat'); } if (['http_proxy', 'https_proxy'].includes(key)) { value = _crypto["default"].proxyEncrypt(value); } rcParser.set(key, value); rcParser.save(); break; case 'delete': if (args.length !== 2) { throw (0, _i18n.getI18nMessage)('config.deleteFormat'); } rcParser["delete"](key); rcParser.save(); break; case 'list': if (options.json) { _i18n["default"].log('common.message', { message: "".concat(JSON.stringify(rcParser.toJson(), null, 4)) }); } else { _i18n["default"].log('common.message', { message: "".concat(rcParser.toString(), "\n") }); } break; case 'get': _i18n["default"].log('common.message', { message: "".concat(rcParser.get(key)) }); break; default: _i18n["default"].log('common.message', { message: "".concat((0, _i18n.getI18nMessage)('config.supportError', { errAction: actionName || '' })) }); break; } };