@@ -4,8 +4,7 @@ import * as path from "path"
44import { field , logger , Level } from "@coder/logger"
55import { Args as VsArgs } from "../../lib/vscode/src/vs/server/ipc"
66import { AuthType } from "./http"
7- import { xdgLocalDir } from "./util"
8- import xdgBasedir from "xdg-basedir"
7+ import { paths , uxPath } from "./util"
98
109export class Optional < T > {
1110 public constructor ( public readonly value ?: T ) { }
@@ -272,7 +271,7 @@ export const parse = (argv: string[]): Args => {
272271 }
273272
274273 if ( ! args [ "user-data-dir" ] ) {
275- args [ "user-data-dir" ] = xdgLocalDir
274+ args [ "user-data-dir" ] = paths . data
276275 }
277276
278277 if ( ! args [ "extensions-dir" ] ) {
@@ -282,6 +281,11 @@ export const parse = (argv: string[]): Args => {
282281 return args
283282}
284283
284+ const defaultConfigFile = `
285+ auth: password
286+ bind-addr: 127.0.0.1:8080
287+ ` . trimLeft ( )
288+
285289// readConfigFile reads the config file specified in the config flag
286290// and loads it's configuration.
287291//
@@ -291,37 +295,39 @@ export const parse = (argv: string[]): Args => {
291295// to ~/.config/code-server/config.yaml.
292296export async function readConfigFile ( args : Args ) : Promise < Args > {
293297 const configPath = getConfigPath ( args )
294- if ( configPath === undefined ) {
295- return args
296- }
297298
298299 if ( ! ( await fs . pathExists ( configPath ) ) ) {
299- await fs . outputFile ( configPath , `default: hello` )
300+ await fs . outputFile ( configPath , defaultConfigFile )
301+ logger . info ( `Wrote default config file to ${ uxPath ( configPath ) } ` )
300302 }
301303
304+ logger . info ( `Using config file from ${ uxPath ( configPath ) } ` )
305+
302306 const configFile = await fs . readFile ( configPath )
303307 const config = yaml . safeLoad ( configFile . toString ( ) , {
304308 filename : args . config ,
305309 } )
306310
307311 // We convert the config file into a set of flags.
308312 // This is a temporary measure until we add a proper CLI library.
309- const configFileArgv = Object . entries ( config ) . map ( ( [ optName , opt ] ) => `--${ optName } =${ opt } ` )
313+ const configFileArgv = Object . entries ( config ) . map ( ( [ optName , opt ] ) => {
314+ if ( opt === null ) {
315+ return `--${ optName } `
316+ }
317+ return `--${ optName } =${ opt } `
318+ } )
310319 const configFileArgs = parse ( configFileArgv )
311320
312321 // This prioritizes the flags set in args over the ones in the config file.
313322 return Object . assign ( configFileArgs , args )
314323}
315324
316- function getConfigPath ( args : Args ) : string | undefined {
325+ function getConfigPath ( args : Args ) : string {
317326 if ( args . config !== undefined ) {
318327 return args . config
319328 }
320329 if ( process . env . CODE_SERVER_CONFIG !== undefined ) {
321330 return process . env . CODE_SERVER_CONFIG
322331 }
323- if ( xdgBasedir . config !== undefined ) {
324- return `${ xdgBasedir . config } /code-server/config.yaml`
325- }
326- return undefined
332+ return path . join ( paths . config , "config.yaml" )
327333}
0 commit comments