question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simplify building commands by wrapping common functionality in a base class

See original GitHub issue

Currently, when building commands, each command has to include pieces such as calling telemetry, checking if user is connected to a service, retrieving request digest, validating URLs, etc. We could simplify building commands, by wrapping all this into a base class.

Following this suggestion from @erwinvanhunen, I put together a proof of concept showing how this would look in practice. SpoCommand is the base class for all SharePoint Online commands. Notice the implementation of common pieces such as requiresTenantAdmin, logging telemetry or checking connection to SharePoint. Additionally, two methods: getRequestDigest and isValidSharePointUrl are added. With this in place, a command can focus on its specific logic without implementing common pieces.

While the SpoCommand class currently defines the verbose getter, that could go to the Command class so that it’s available to all commands in the CLI. For the PoC I didn’t restructure everything as I just wanted to see how it would work on a few commands.

What do you think: would the gained simplification be worth the effort to refactor the existing commands? @estruyf, @wictorwilen, @andrewconnell

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
erwinvanhunencommented, Nov 19, 2017

Absolutely valuable. Having this code in all cmdlets makes it complex to change if requirements change later, also it’s pretty error prone (copy and paste errors). I would absolutely move -verbose to the base class, Also think of including parameters (alike PowerShell) for error handling (failsilently, ignore, etc.)

1reaction
andrewconnellcommented, Nov 20, 2017

Sorry but I don’t have any CLI examples or have much insight into your questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SWIG and C++ - SWIG.org
Comments on C++ Wrapping; Approach; Supported C++ features; Command line options and ... These wrappers take care of basic type conversion, type checking, ......
Read more >
c# - Generic Base Class Overriding Non ... - Stack Overflow
I have a heirarchy of command classes. At the most abstract level I have an ICommand interface. The result from executing an ICommand's ......
Read more >
Primer on Python Decorators
Put simply: decorators wrap a function, modifying its behavior. Before moving on, let's have a look at a second example. Because wrapper() is...
Read more >
Decorator - Refactoring.Guru
Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that...
Read more >
Chapter 10: Object-Oriented Programming in LabVIEW
This chapter discusses the basic methodology of object coding, and also dis- ... do some kind of work, but the specifics of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found