{"size": 1788, "ext": "js", "max_stars_repo_path": "src/store/modules/cli.js", "max_stars_repo_name": "lukasf98/ui", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/modules/cli.js", "max_issues_repo_name": "lukasf98/ui", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/store/modules/cli.js", "max_forks_repo_name": "lukasf98/ui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.2207792208, "max_line_length": 53, "alphanum_fraction": 0.5391498881}
const axios = require('axios');

const cli = {
  namespaced: true,

  state: {
    cli: undefined,
    prompt: undefined,
    commands: undefined,
    message: undefined,
    actions: {},
    steps: [],
  },
  mutations: {
    startCli: (state, data) => {
      state.cli = true;
      state.prompt = data.prompt;
      if (data.commands) {
        state.commands = data.commands;
      }
    },
    stopCli: (state) => {
      state.cli = undefined;
      state.prompt = undefined;
      state.commands = undefined;
      state.message = undefined;
      state.steps = [];
    },
    clearCliError: (state) => {
      state.message = undefined;
    },
    setCliError: (state, data) => {
      if (!state) return;
      state.message = data.message;
    },
    addStep: (state, step) => {
      if (!state.cli || !step.store) return;
      if (step.result !== 'passed') return;
      if (!step.store.debugMode) return;
      state.steps.push(step);
    }
  },
  getters: {
    steps: state => state.steps,
    show: state => {
      return state.cli !== undefined;
    },
    actions: state => state.actions,
  },
  actions: {
    loadActions: async ({ state }) => {
      try {
        const resp = await axios.get('/api/actions');
        state.actions = resp.data.actions;
      } catch (err) {
        state.actions = {};
      }
    },
    'SOCKET_cli.start': function ({ commit }, data) {
      commit('startCli', data);
    },
    'SOCKET_cli.stop': function ({ commit }, data) {
      commit('stopCli', data);
    },
    'SOCKET_cli.output': function () {
    },
    'SOCKET_cli.error': function ({ commit }, data) {
      commit('setCliError', data);
    },
    'SOCKET_step.before': function ({commit}, step) {
      commit('addStep', step);
    },
  }
};

export default cli;
