dcli
  • Introduction
  • What does DCli do?
  • Install DCli
    • Installing on Windows
  • Writing your first CLI app
  • Add DCli to your project
  • pub.dev
  • github
  • Dart basics
    • Dart lambda functions
    • Function Arguments
    • Futures
    • stdin/stdout/stderr a primer
  • Tour
    • Overview
    • Using DCli functions
    • User input
      • Ask Validators
    • Displaying information
    • Managing Files And Directories
    • Environment variables
    • Calling apps
    • Redirecting output
    • Command Line Arguments
    • Paths
    • Glob Expansion
    • Piping
    • Locking
    • Fetch
    • The evils of CD
    • Assets/Resources
    • Cross Platform
      • Posix
      • Windows
      • Docker
        • Detecting Docker
        • Add DCli to a Docker Container
        • Example DCli app in Docker
  • Elevated Privileges
    • Sudo
  • Performance
  • Dependency Management
    • Dependency Management
    • Pubspec Managment
  • DCli Tools
    • DCli tools
    • Use a shebang #!
    • DCli Compile
    • DCli Clean
    • DCli Create
    • DCli Doctor
    • DCli Install
    • DCli Run
    • DCli Warmup
    • DCli Pack
    • Upgrade DCli
  • Internal Workings
    • Internal Workings
    • waitForEx
  • Contributing
    • Creating a release
    • Running Unit tests
    • Implemention support for a shell
    • Templates
  • References
  • Examples
    • Projects
    • Code
      • hello world.
      • dcompress
      • dpath
      • dmysql
      • dshell
      • dwhich
      • dipaddr
      • gnome launcher
  • Articles
    • build CLI apps in dart - part 1
    • build CLI apps in dart - part 2
    • Dealing with permissions
    • 3rd Party console packages
  • Dart on Linux - the perfect CLI tooling
  • Improving your build environment
    • Existing tooling
    • Building with Dart
    • A home for your build tools
  • Olivier Revial - CLI apps made easy
  • Video: package of the week
Powered by GitBook
On this page
  • Windows
  • Linux/OSX

Was this helpful?

Elevated Privileges

Often you need to run a script with elevated privileges.

On Linux and OSX this means using sudo, on Windows it means using 'Run as Administrator'.

DCli abstracts Linux/OSX sudo and Windows Administrator into a single concept of 'elevated privileges'.

In DCli you can check if your script is running with elevated privileges by calling isPrivilegedUser

 if (!Shell.current.isPrivilegedUser) {
    printerr(
       'Please restart ${Script.current.exeName} using with elevated privileges');
    exit(1);
  }

Windows

Under Windows elevated privileges are pretty simple.

If any part of your script needs to run with elevated privileges then just use the 'Run as Administrator' option in windows.

You should add a call to Shell.current.isPrivilegedUser at the start of the script and force users to restart with the required privileges.

Linux/OSX

Under Linux/OSX privileged operations for more problematic.

If you need the entire script to run escalated then use the above isPrivilegedUser method however often you will want to only use escalated privileges for some of the script which is possible with the Shell.current.withPriviliged method.

PreviousExample DCli app in DockerNextSudo

Last updated 2 years ago

Was this helpful?

Read the page on for additional details and some of the problems you will encounter and how to solve them.

sudo