Skip to content

Commit

Permalink
Fix git init
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Apr 22, 2024
1 parent d0fa8bf commit beb2ba5
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions lib/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ async function main() {
* - Or generate configuration using (init)
*/
const runWithoutConfig = baseArgument == "run" && (cmd !== undefined || checkedArgs.get("worker") !== undefined)
const useConfigFile = !runWithoutConfig
const useConfigFile = !runWithoutConfig && baseArgument !== "init"
let configFile
if (useConfigFile) {
const configFileCwd = toResolvedAbsolutePath(checkedArgs?.get("cwd") || cwd())
configFile = await findConfigFile(configFileCwd, useConfigFile, checkedArgs?.get("config"))
}
}
// Exit if a configuration file is expected, but not found
if (useConfigFile && !configFile) {
console.error("Configuration file not found.")
Expand All @@ -148,6 +148,23 @@ async function main() {
return exit(1)
}
}
/**
* Base argument: init
*
* Generate a new configuration file and exit
*/
if (baseArgument === "init") {
// Default new configuration file to pup.json
const fallbackedConfigFile = configFile ?? "pup.json"
if (await exists(fallbackedConfigFile)) {
console.error(`Configuration file '${fallbackedConfigFile}' already exists, exiting.`)
exit(1)
} else {
await createConfigurationFile(fallbackedConfigFile, checkedArgs!, cmd!)
console.log(`Configuration file '${fallbackedConfigFile}' created`)
exit(0)
}
}
// Read or generate configuration
let configuration: Configuration
if (configFile) {
Expand Down Expand Up @@ -210,27 +227,9 @@ async function main() {
}

/**
* Base argument: init
* Base argument: token
*
* Generate a new configuration file and exit
*/
if (baseArgument === "init") {
// Default new configuration file to pup.json
const fallbackedConfigFile = configFile ?? "pup.json"
if (await exists(fallbackedConfigFile)) {
console.error(`Configuration file '${fallbackedConfigFile}' already exists, exiting.`)
exit(1)
} else {
await createConfigurationFile(fallbackedConfigFile, checkedArgs!, cmd!)
console.log(`Configuration file '${fallbackedConfigFile}' created`)
exit(0)
}
}

/**
* Base argument: init
*
* Generate a new configuration file and exit
* Generate a new api token and exit
*/
if (baseArgument === "token") {
if (secret) {
Expand Down

0 comments on commit beb2ba5

Please sign in to comment.