You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tsparser-encore.rs
    path of file: ./repos/encore/tsparser/src/bin
    
    the code of the file until where you have to start completion: use std::collections::HashMap;
use std::io::{self, BufRead, Write};
use std::path::PathBuf;

use anyhow::Result;
use prost::Message;
use serde::{Deserialize, Serialize};
use swc_common::{Globals, GLOBALS};

use encore_tsparser::builder;
use encore_tsparser::builder::Builder;
use encore_tsparser::parser::parser::ParseContext;

fn main() -> Result<()> {
    env_logger::init();
    let cwd = std::env::current_dir()?;

    let js_runtime_path = std::env::var("ENCORE_JS_RUNTIME_PATH")
        .map(PathBuf::from)
        .expect("ENCORE_JS_RUNTIME_PATH not set");

    let globals = Globals::new();
    GLOBALS.set(&globals, || {
        let builder = Builder::new()?;
        let mut parse: Option<(builder::App, builder::ParseResult)> = None;

        let mut pc = ParseContext::new(&js_runtime_path);

        loop {
            let Some(cmd) = parse_cmd()? else { continue };
            match cmd {
                Command::Prepare(input) => {
                    log::debug!("got prepare input {:?}", input);
                    let pp = builder::PrepareParams {
                        js_runtime_root: &js_runtime_path,
                        runtime_version: &input.runtime_version,
                        app_root: &input.app_root,
              
    
fn main() -> Result<()> {
    env_logger::init();
    let cwd = std::env::current_dir()?;

    let js_runtime_path = std::env::var("ENCORE_JS_RUNTIME_PATH")
        .map(PathBuf::from)
        .expect("ENCORE_JS_RUNTIME_PATH not set");

    let globals = Globals::new();
    GLOBALS.set(&globals, || {
        let builder = Builder::new()?;
        let mut parse: Option<(builder::App, builder::ParseResult)> = None;

        let mut pc = ParseContext::new(&js_runtime_path);

        loop {
            let Some(cmd) = parse_cmd()? else { continue };
            match cmd {
                Command::Prepare(input) => {
                    log::debug!("got prepare input {:?}", input);
                    let pp = builder::PrepareParams {
                        js_runtime_root: &js_runtime_path,
                        runtime_version: &input.runtime_version,
                        app_root: &input.app_root,
                        use_local_runtime: input.use_local_runtime,
                    };
                    match builder.prepare(&pp) {
                        Ok(result) => {
                            let json = serde_json::to_string(&result)?;
                            write_result(Ok(json.as_bytes()))?;
                        }
                        Err(err) => {
                            log::error!("failed to prepare: {:?}", err);
                            write_result(Err(err))?
                        }
                    }
                }

                Command::Parse(input) => {
                    log::debug!("got parse input {:?}", input);
                    if parse.is_some() {
                        anyhow::bail!("already parsed!");
                    }

                    let app = builder::App {
                        root: input.app_root.clone(),
                        platform_id: input.platform_id,
                        local_id: input.local_id,
                    };

                    pc.dir_roots = vec![input.app_root];
                    let pp = builder::ParseParams {
                        app: &app,
                        pc: &pc,
                        working_dir: &cwd,
                        parse_tests: input.parse_tests,
                    };

                    match builder.parse(&pp) {
                        Ok(result) => {
                            write_result(Ok(result.desc.meta.encode_to_vec().as_slice()))?;
                            parse = Some((app, result));
                        }
                        Err(err) => {
                            log::error!("failed to parse: {:?}", err);
                            write_result(Err(err))?
                        }
                    }
                }

                Command::Compile(input) => match &parse {
                    None => anyhow::bail!("no parse!"),
                    Some((app, parse)) => {
                        let cp = builder::CompileParams {
                            js_runtime_root: &js_runtime_path,
                            runtime_version: &input.runtime_version,
                            app,
                            pc: &pc,
                            working_dir: &cwd,
                            parse: &parse,
                            use_local_runtime: input.use_local_runtime,
                        };

                        match builder.compile(&cp) {
                            Ok(compile) => {
                                let json = serde_json::to_string(&compile)?;
                                write_result(Ok(json.as_bytes()))?;
                            }
                            Err(err) => {
                                log::error!("failed to compile: {:?}", err);
                                write_result(Err(err))?
                            }
                        };
                    }
                },

                Command::Test(input) => match &parse {
                    None => anyhow::bail!("no parse!"),
                    Some((app, parse)) => {
                        let p = builder::TestParams {
                            js_runtime_root: &js_runtime_path,
                            runtime_version: &input.runtime_version,
                            app,
                            pc: &pc,
                            working_dir: &cwd,
                            parse: &parse,
                            use_local_runtime: input.use_local_runtime,
                        };

                        match builder.test(&p) {
                            Ok(compile) => {
                                let json = serde_json::to_string(&compile)?;
                                write_result(Ok(json.as_bytes()))?;
                            }
                            Err(err) => {
                                log::error!("failed to run tests: {:?}", err);
                                write_result(Err(err))?
                            }
                        };
                    }
                },

                Command::GenUserFacing(input) => match &parse {
                    None => anyhow::bail!("no parse!"),
                    Some((app, parse)) => {
                        let cp = builder::CodegenParams {
                            js_runtime_root: &js_runtime_path,
                            app,
                            pc: &pc,
                            working_dir: &cwd,
                            parse: &parse,
                        };

                        match builder.generate_code(&cp) {
                            Ok(_) => write_result(Ok(&[]))?,
                            Err(err) => {
                                log::error!("failed to generate code: {:?}", err);
                                write_result(Err(err))?
                            }
                        };
                    }
                },
            }
        }
    })
}