Skip to content

Commit

Permalink
Add pkg help command
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemartinlogan committed Feb 6, 2024
1 parent d5fd98c commit 0f668b9
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 6 deletions.
98 changes: 94 additions & 4 deletions bin/jarvis
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ class JarvisArgs(ArgParse):
self.add_menu('pipeline update', msg='Re-run configure on all pkgs '
'in a pipeline')


# jarvis pipeline append
self.add_menu('pipeline append',
msg='Append a pkg to a pipeline',
Expand Down Expand Up @@ -599,10 +600,49 @@ class JarvisArgs(ArgParse):
"to track certain variables.",
keep_remainder=True)

# jarvis pipeline
# jarvis pipeline env path
self.add_menu('pipeline env path',
msg='Get the path to the pipeline env file')
self.add_args([
{
'name': 'pipeline_id',
'msg': 'A unique name for this pipeline',
'required': False,
'pos': True,
'default': None
},
])

# jarvis pipeline env show
self.add_menu('pipeline env show',
msg='View the jarvis env file')
self.add_args([
{
'name': 'pipeline_id',
'msg': 'A unique name for this pipeline',
'required': False,
'pos': True,
'default': None
},
])

# jarvis pkg
self.add_menu('pkg',
msg='Tools to edit pkgs in a pipeline')

# jarvis pkg help
self.add_menu('pkg help',
msg='View the help menu for a package')
self.add_args([
{
'name': 'pkg_type',
'msg': 'The type of pkg being added to the pipeline',
'required': True,
'pos': True,
'default': None
},
])

# jarvis pkg configure
self.add_menu('pkg configure',
msg="Configure a pkg in the pipeline",
Expand Down Expand Up @@ -928,7 +968,7 @@ class JarvisArgs(ArgParse):

# jarvis env destroy
self.add_menu('env destroy',
msg="Destroy a custom environment.")
msg='Destroy a custom environment.')
self.add_args([
{
'name': 'env_name',
Expand All @@ -939,13 +979,39 @@ class JarvisArgs(ArgParse):
},
])

# jarvis env path
self.add_menu('env path',
msg='View the environment file\'s path')
self.add_args([
{
'name': 'env_name',
'msg': 'The name of the environment to show',
'required': True,
'pos': True,
'default': None
},
])

# jarvis env show
self.add_menu('env show',
msg='View the environment file\'s output')
self.add_args([
{
'name': 'env_name',
'msg': 'The name of the environment to show',
'required': True,
'pos': True,
'default': None
},
])

# jarvis env list
self.add_menu('env list',
msg="List all custom environments.")
msg='List all custom environments.')

# jarvis pipeline env copy
self.add_menu('pipeline env copy',
msg="Copy and modify a custom environment.",
msg='Copy and modify a custom environment.',
keep_remainder=True,
remainder_as_kv=True)
self.add_args([
Expand Down Expand Up @@ -1085,6 +1151,12 @@ class JarvisArgs(ArgParse):
kwargs.update(self.remainder_kv)
Pipeline().build_static_env(kwargs['env_name'], kwargs)

def env_path(self):
print(Pipeline().get_static_env_path(self.kwargs['env_name']))

def env_show(self):
Pipeline().static_env_show(self.kwargs['env_name'])

def env_destroy(self):
Pipeline().destroy_static_env(self.kwargs['env_name'])

Expand Down Expand Up @@ -1161,6 +1233,16 @@ class JarvisArgs(ArgParse):
Pipeline().load(pipeline_id, with_config=False).reset()
self.jarvis.save()

def pipeline_env_path(self):
pipeline_id = self.kwargs['pipeline_id']
pipeline = Pipeline().load(pipeline_id)
print(pipeline.env_path)

def pipeline_env_show(self):
pipeline_id = self.kwargs['pipeline_id']
pipeline = Pipeline().load(pipeline_id)
pipeline.env_show()

def pipeline_destroy(self):
pipeline_id = self.kwargs['pipeline_id']
Pipeline().load(pipeline_id).destroy()
Expand Down Expand Up @@ -1243,6 +1325,14 @@ class JarvisArgs(ArgParse):
def pkg_remove(self):
Pipeline().load().remove(self.kwargs['pkg_id']).save()

def pkg_help(self):
pkg_type = self.kwargs['pkg_type']
pkg = self.jarvis.construct_pkg(pkg_type)
menu = pkg.configure_menu()
args = PkgArgParse(args=[], menu=menu)
args.binary_name = pkg_type
args._print_help()

def pkg_configure(self):
pipeline = Pipeline().load()
pkg = pipeline.get_pkg(self.kwargs['pkg_id'])
Expand Down
29 changes: 27 additions & 2 deletions jarvis_cd/basic/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from jarvis_util.shell.filesystem import Mkdir
from jarvis_util.shell.pssh_exec import PsshExecInfo
from enum import Enum
import yaml
import inspect
import pathlib
import shutil
Expand Down Expand Up @@ -337,6 +338,9 @@ def get_pkg(self, pkg_id):
def view_pkgs(self):
print(self.to_string_pretty())

def env_show(self):
print(yaml.dump(self.env))

def update_env(self, env, mod_env=None):
"""
Update the current environment for this program
Expand Down Expand Up @@ -840,6 +844,15 @@ def from_yaml(self, path, do_configure=True):
config = YamlFile(path).load()
return self.from_dict(config, do_configure)

def get_static_env_path(self, env_name):
"""
Get the path to the static environment
:param env_name: The name of the environment
:return: str
"""
return os.path.join(self.jarvis.env_dir, f'{env_name}.yaml')

def copy_static_env(self, env_name, env_track_dict=None):
"""
Copy a cached environment to this pipeline
Expand All @@ -849,20 +862,32 @@ def copy_static_env(self, env_name, env_track_dict=None):
to track the environment variable, which are the keys of the dict.
:return: self
"""
static_env_path = os.path.join(self.jarvis.env_dir, f'{env_name}.yaml')
static_env_path = self.get_static_env_path(env_name)
self.env = YamlFile(static_env_path).load()
self.track_env(env_track_dict)
self.update()
return self

def static_env_show(self, env_name):
"""
View the contents of the static environment
:param env_name: The name of the environment to show
:return: self
"""
static_env_path = self.get_static_env_path(env_name)
env = YamlFile(static_env_path).load()
print(yaml.dump(env))
return self

def destroy_static_env(self, env_name):
"""
Destroy a static environment file
:param env_name: The name of the environment to create
:return: self
"""
static_env_path = os.path.join(self.jarvis.env_dir, f'{env_name}.yaml')
static_env_path = self.get_static_env_path(env_name)
os.remove(static_env_path)
return self

Expand Down

0 comments on commit 0f668b9

Please sign in to comment.