| 238 | |
| 239 | |
| 240 | class PackInstallCommand(PackAsyncCommand): |
| 241 | def __init__(self, resource, *args, **kwargs): |
| 242 | super(PackInstallCommand, self).__init__( |
| 243 | resource, |
| 244 | "install", |
| 245 | "Install new %s." % resource.get_plural_display_name().lower(), |
| 246 | *args, |
| 247 | **kwargs, |
| 248 | ) |
| 249 | |
| 250 | self.parser.add_argument( |
| 251 | "packs", |
| 252 | nargs="+", |
| 253 | metavar="pack", |
| 254 | help="Name of the %s in Exchange, or a git repo URL." |
| 255 | % resource.get_plural_display_name().lower(), |
| 256 | ) |
| 257 | self.parser.add_argument( |
| 258 | "--force", |
| 259 | action="store_true", |
| 260 | default=False, |
| 261 | help="Force pack installation.", |
| 262 | ) |
| 263 | self.parser.add_argument( |
| 264 | "--skip-dependencies", |
| 265 | action="store_true", |
| 266 | default=False, |
| 267 | help="Skip pack dependency installation.", |
| 268 | ) |
| 269 | |
| 270 | def run(self, args, **kwargs): |
| 271 | is_structured_output = args.json or args.yaml |
| 272 | |
| 273 | # If structured output is requested, do not print information about contents of pack |
| 274 | # This information is already exposed via st2 pack show ${pack_name} -j |
| 275 | if not is_structured_output: |
| 276 | self._get_content_counts_for_pack(args, **kwargs) |
| 277 | |
| 278 | return self.manager.install( |
| 279 | args.packs, |
| 280 | force=args.force, |
| 281 | skip_dependencies=args.skip_dependencies, |
| 282 | **kwargs, |
| 283 | ) |
| 284 | |
| 285 | def _get_content_counts_for_pack(self, args, **kwargs): |
| 286 | # Global content list, excluding "tests" |
| 287 | # Note: We skip this step for local packs |
| 288 | pack_content = { |
| 289 | "actions": 0, |
| 290 | "rules": 0, |
| 291 | "sensors": 0, |
| 292 | "aliases": 0, |
| 293 | "triggers": 0, |
| 294 | } |
| 295 | |
| 296 | if len(args.packs) == 1: |
| 297 | args.pack = args.packs[0] |