src/commands/logs.js
/**
   * An asyncronous handler for the user attempting to navigate logs while streaming.
   *
   * @returns {Promise<boolean>} Reutrns a promise that resolves to a boolean whether the application should continue (or exit)
   */
An asyncronous handler for the user attempting to navigate logs while streaming.
@returns {Promise} Reutrns a promise that resolves to a boolean whether the application should continue (or exit)
An asyncronous handler for the user attempting to navigate logs while streaming . @returns { Promise } Reutrns a promise that resolves to a boolean whether the application should continue ( or exit )
async handleNavigation() {
    try {
      await this.waitForKeyPress('up')
    } catch (error) {
      return false
    }
    if (this.logs.length === 0) {
      return this.handleNavigation()
    }
    this.canLog = false
    const log = await this.promptForLog()
    if (!log) {
      this.clearScreen()
      await this.printLogs()
      this.canLog = true
      return this.handleNavigation()
    }
    this.spinner('Fetching log from Chec...')
    try {
      await log.getFullLog()
    } catch (error) {
      throw new Error(`Failed to fetch full log detail from Chec. (${error.response.statusCode})`)
    }
    this.spinner(null)
    const {flags: {utc}} = this.parse(LogsCommand)
    this.clearScreen()
    this.log(chalk.dim(log.formattedSummary(utc)))
    this.log(await log.formattedLog())
    this.log('')
    this.log('Press "enter" to return to streaming logs or "c" to copy to clipboard')
    this.waitForKeyPress('c').then(async () => {
      clipboardy.write(JSON.stringify(await log.getFullLog(), null, 2))
    }).catch(() => {})
    try {
      await this.waitForKeyPress('return')
    } catch (error) {
      return false
    }
    this.clearScreen()
    return true
  }
async handleNavigation ( ) { try { await this . waitForKeyPress ( 'up' ) } catch ( error ) { return false } if ( this . logs . length === 0 ) { return this . handleNavigation ( ) } this . canLog = false const log = await this . promptForLog ( ) if ( ! log ) { this . clearScreen ( ) await this . printLogs ( ) this . canLog = true return this . handleNavigation ( ) } this . spinner ( 'Fetching log from Chec...' ) try { await log . getFullLog ( ) } catch ( error ) { throw new Error ( ` ${ error . response . statusCode } ` ) } this . spinner ( null ) const { flags : { utc } } = this . parse ( LogsCommand ) this . clearScreen ( ) this . log ( chalk . dim ( log . formattedSummary ( utc ) ) ) this . log ( await log . formattedLog ( ) ) this . log ( '' ) this . log ( 'Press "enter" to return to streaming logs or "c" to copy to clipboard' ) this . waitForKeyPress ( 'c' ) . then ( async ( ) => { clipboardy . write ( JSON . stringify ( await log . getFullLog ( ) , null , 2 ) ) } ) . catch ( ( ) => { } ) try { await this . waitForKeyPress ( 'return' ) } catch ( error ) { return false } this . clearScreen ( ) return true }
An asyncronous handler for the user attempting to navigate logs while streaming.
An asyncronous handler for the user attempting to navigate logs while streaming .
// "up" launches into an interactive session to get full versions of prior logs. Skip anything else // Don't do anything if there's no logs, just keep waiting for input // Ensure we don't log now // Ask the user for a log // If the user cancelled, go back to waiting // Fetch the individual log entry // Fetch the UTC preference from command flags // Clear the screen and display the log // Register a handler to copy the response and ignore any failures // Wait for them to press enter // Clean up the console for the logs to be displayed again