@dynamicweb/cli
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -43,4 +43,16 @@ import { updateConfig, getConfig } from './config.js' | ||
export async function setupEnv(argv) { | ||
let env; | ||
if (getConfig().env) { | ||
let env = {}; | ||
let askEnv = true; | ||
if (argv.host) { | ||
askEnv = false; | ||
env.host = argv.host; | ||
if (argv.protocol) { | ||
env.protocol = argv.protocol; | ||
} else { | ||
env.protocol = 'https'; | ||
} | ||
} | ||
if (askEnv && getConfig().env) { | ||
env = getConfig().env[argv.env] || getConfig().env[getConfig()?.current?.env]; | ||
@@ -52,3 +64,3 @@ if (!env.protocol) { | ||
} | ||
if (!env) { | ||
else if (askEnv) { | ||
console.log('Current environment not set, please set it') | ||
@@ -55,0 +67,0 @@ await interactiveEnv(argv, { |
@@ -21,7 +21,20 @@ import fetch from 'node-fetch'; | ||
export async function setupUser(argv, env) { | ||
let user; | ||
if (env.users) { | ||
let user = {}; | ||
let askLogin = true; | ||
if (argv.apiKey) { | ||
user.apiKey = argv.apiKey; | ||
askLogin = false; | ||
} | ||
if (!user.apiKey && env.users) { | ||
user = env.users[argv.user] || env.users[env.current.user]; | ||
askLogin = false; | ||
} | ||
if (!user) { | ||
if (askLogin && argv.host) { | ||
console.log('Please add an --apiKey to the command as overriding the host requires that.') | ||
process.exit(); | ||
} | ||
else if (askLogin) { | ||
console.log('Current user not set, please login') | ||
@@ -46,2 +59,3 @@ await interactiveLogin(argv, { | ||
} | ||
return user; | ||
@@ -48,0 +62,0 @@ } |
@@ -34,2 +34,11 @@ #! /usr/bin/env node | ||
}) | ||
.option('protocol', { | ||
description: 'Allows setting the protocol used, only used together with --host, defaulting to https' | ||
}) | ||
.option('host', { | ||
description: 'Allows setting the host used, only allowed if an --apiKey is specified' | ||
}) | ||
.option('apiKey', { | ||
description: 'Allows setting the apiKey for an environmentless execution of the CLI command' | ||
}) | ||
.demandCommand() | ||
@@ -36,0 +45,0 @@ .parse() |
@@ -5,3 +5,3 @@ { | ||
"description": "Dynamicweb CLI is a commandline tool for interacting with Dynamicweb 10 solutions.", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "bin/index.js", | ||
@@ -8,0 +8,0 @@ "files": [ |
50817
1096