Merge branch '15-new-cli' into 'master'
Resolve "Investigate usage of new cli (like the gcloud one)" Closes #15 See merge request icaotix/linux-tools!10
This commit is contained in:
commit
b600d902ba
18
main.py
18
main.py
@ -1,6 +1,6 @@
|
|||||||
from PyInquirer import prompt
|
|
||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
|
import fire
|
||||||
|
|
||||||
|
|
||||||
def load_modules():
|
def load_modules():
|
||||||
@ -16,19 +16,5 @@ def load_modules():
|
|||||||
return loaded_modules
|
return loaded_modules
|
||||||
|
|
||||||
|
|
||||||
def open_module_selection(module_names):
|
|
||||||
print("Available Modules:")
|
|
||||||
module_selection = [
|
|
||||||
{
|
|
||||||
'type': 'checkbox',
|
|
||||||
'message': 'Select modules',
|
|
||||||
'name': 'modules',
|
|
||||||
'choices': list(map(lambda x: {"name": x}, list(module_names)))
|
|
||||||
}
|
|
||||||
]
|
|
||||||
return prompt(module_selection)['modules']
|
|
||||||
|
|
||||||
|
|
||||||
modules = load_modules()
|
modules = load_modules()
|
||||||
|
fire.Fire(modules)
|
||||||
[modules[module].run() for module in open_module_selection(modules.keys())]
|
|
||||||
|
@ -8,37 +8,39 @@ from PyInquirer import prompt
|
|||||||
from AbstractModule import AbstractModule
|
from AbstractModule import AbstractModule
|
||||||
|
|
||||||
|
|
||||||
def get_vim_root():
|
|
||||||
# return Path(os.getcwd()).joinpath("devenv", ".vim")
|
|
||||||
return Path().home().joinpath(".vim")
|
|
||||||
|
|
||||||
|
|
||||||
class VimModule(AbstractModule):
|
class VimModule(AbstractModule):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.json_config = {}
|
self._debugFlag = False
|
||||||
|
self._json_config = {}
|
||||||
with open("modules/vim/vimrc_conf.json") as plugins:
|
with open("modules/vim/vimrc_conf.json") as plugins:
|
||||||
self.json_config = json.load(plugins)
|
self._json_config = json.load(plugins)
|
||||||
|
|
||||||
def create_folder_structure(self):
|
def _get_vim_root(self):
|
||||||
os.makedirs(str(get_vim_root().joinpath("autoload")), exist_ok=True)
|
if self._debugFlag:
|
||||||
os.makedirs(str(get_vim_root().joinpath("plugged")), exist_ok=True)
|
return Path(os.getcwd()).joinpath("devenv", ".vim")
|
||||||
|
else:
|
||||||
|
return Path().home().joinpath(".vim")
|
||||||
|
|
||||||
def get_vimplug_file(self):
|
def _create_folder_structure(self):
|
||||||
vimplug_filepath = Path(str(get_vim_root().joinpath("autoload")))
|
os.makedirs(str(self._get_vim_root().joinpath("autoload")), exist_ok=True)
|
||||||
|
os.makedirs(str(self._get_vim_root().joinpath("plugged")), exist_ok=True)
|
||||||
|
|
||||||
|
def _get_vimplug_file(self):
|
||||||
|
vimplug_filepath = Path(str(self._get_vim_root().joinpath("autoload")))
|
||||||
print(vimplug_filepath)
|
print(vimplug_filepath)
|
||||||
if os.path.isfile(str(get_vim_root().joinpath("autoload", "plug.vim"))):
|
if os.path.isfile(str(self._get_vim_root().joinpath("autoload", "plug.vim"))):
|
||||||
print("Vimplug already installed!")
|
print("Vimplug already installed!")
|
||||||
else:
|
else:
|
||||||
curl_request = "curl {} -o {}".format(
|
curl_request = "curl {} -o {}".format(
|
||||||
self.json_config['pluginmanager_url'],
|
self._json_config['pluginmanager_url'],
|
||||||
str(get_vim_root().joinpath("autoload", "plug.vim"))
|
str(self._get_vim_root().joinpath("autoload", "plug.vim"))
|
||||||
)
|
)
|
||||||
subprocess.call(curl_request, shell=True)
|
subprocess.call(curl_request, shell=True)
|
||||||
|
|
||||||
def create_plugin_section(self):
|
def _create_plugin_section(self):
|
||||||
vimrc_content = []
|
vimrc_content = []
|
||||||
plugins = self.json_config['plugins']
|
plugins = self._json_config['plugins']
|
||||||
print("Available Plugins:")
|
print("Available Plugins:")
|
||||||
plugin_selection = [
|
plugin_selection = [
|
||||||
{
|
{
|
||||||
@ -50,7 +52,7 @@ class VimModule(AbstractModule):
|
|||||||
]
|
]
|
||||||
selected_plugins = prompt(plugin_selection)['modules']
|
selected_plugins = prompt(plugin_selection)['modules']
|
||||||
if len(selected_plugins) > 0:
|
if len(selected_plugins) > 0:
|
||||||
self.get_vimplug_file()
|
self._get_vimplug_file()
|
||||||
print("\033[4mYour selection:\033[0m")
|
print("\033[4mYour selection:\033[0m")
|
||||||
[print(x) for x in selected_plugins]
|
[print(x) for x in selected_plugins]
|
||||||
|
|
||||||
@ -61,8 +63,8 @@ class VimModule(AbstractModule):
|
|||||||
|
|
||||||
return vimrc_content
|
return vimrc_content
|
||||||
|
|
||||||
def create_setting_section(self):
|
def _create_setting_section(self):
|
||||||
default_settings = list(self.json_config['settings'].values())
|
default_settings = list(self._json_config['settings'].values())
|
||||||
|
|
||||||
print("\n\033[4mDefault settings:\033[0m")
|
print("\n\033[4mDefault settings:\033[0m")
|
||||||
[print(i) for i in default_settings]
|
[print(i) for i in default_settings]
|
||||||
@ -70,8 +72,8 @@ class VimModule(AbstractModule):
|
|||||||
vimrc_content = list(map(lambda x: x + "\n", default_settings))
|
vimrc_content = list(map(lambda x: x + "\n", default_settings))
|
||||||
return vimrc_content
|
return vimrc_content
|
||||||
|
|
||||||
def get_vimfile_working_copy(self):
|
def _get_vimfile_working_copy(self):
|
||||||
vimrc_path = str(get_vim_root().joinpath(".vimrc"))
|
vimrc_path = str(self._get_vim_root().joinpath(".vimrc"))
|
||||||
try:
|
try:
|
||||||
with open(vimrc_path, "r") as vimrc_file:
|
with open(vimrc_path, "r") as vimrc_file:
|
||||||
vimrc_content = vimrc_file.readlines()
|
vimrc_content = vimrc_file.readlines()
|
||||||
@ -80,23 +82,25 @@ class VimModule(AbstractModule):
|
|||||||
|
|
||||||
return vimrc_content
|
return vimrc_content
|
||||||
|
|
||||||
def write_vimfile(self, vimrc_content):
|
def _write_vimfile(self, vimrc_content):
|
||||||
seen = set()
|
seen = set()
|
||||||
seen_add = seen.add
|
seen_add = seen.add
|
||||||
vimrc_content = [x1 for x1 in vimrc_content if not (x1 in seen or seen_add(x1))]
|
vimrc_content = [x1 for x1 in vimrc_content if not (x1 in seen or seen_add(x1))]
|
||||||
|
|
||||||
vimrc_path = str(get_vim_root().joinpath(".vimrc"))
|
vimrc_path = str(self._get_vim_root().joinpath(".vimrc"))
|
||||||
with open(vimrc_path, "w") as vimrc_file:
|
with open(vimrc_path, "w") as vimrc_file:
|
||||||
for line in vimrc_content:
|
for line in vimrc_content:
|
||||||
vimrc_file.write(line)
|
vimrc_file.write(line)
|
||||||
|
|
||||||
def exec_plugin_manager(self):
|
def _exec_plugin_manager(self):
|
||||||
install_plugins = "vim +PlugInstall +qall +silent"
|
install_plugins = "vim +PlugInstall +qall +silent"
|
||||||
subprocess.call(install_plugins, shell=True)
|
subprocess.call(install_plugins, shell=True)
|
||||||
|
|
||||||
def run(self):
|
def run(self, debug=False):
|
||||||
self.create_folder_structure()
|
if debug:
|
||||||
plugin_section = self.create_plugin_section()
|
self._debugFlag = True
|
||||||
settings_section = self.create_setting_section()
|
self._create_folder_structure()
|
||||||
self.write_vimfile(settings_section + plugin_section)
|
plugin_section = self._create_plugin_section()
|
||||||
self.exec_plugin_manager()
|
settings_section = self._create_setting_section()
|
||||||
|
self._write_vimfile(settings_section + plugin_section)
|
||||||
|
self._exec_plugin_manager()
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
fire
|
||||||
PyInquirer==1.0.3
|
PyInquirer==1.0.3
|
||||||
|
Loading…
Reference in New Issue
Block a user